c++小例子代码(1)
给一个不多于5位的正整数,要求:一、求它是几位数,二、逆序打印出各位数字。[cpp]
#include<iostream>
int digit(int,int&);
int order(int,int);
int main(int argc,int argv[]){
int number = 0;
int count = 0;
printf("请输入一个不多于5位的数:");
scanf("%d",&number);
digit(number,count);
printf("位数=%d\n",count);
order(number,count);
return 0;
}
int digit(int x,int& y){
while(x>0){
x = x/10;
y++;
}
return 0;
}
int order(int x,int y){
int a = 0;
int c = 0;
int d = 0;
for(int i=1;i<=y;i++){
int b = 1;
for(int j=1;j<=i;j++){
b *= 10;
}
a=(x%b-c);
d = a/(b/10);
c=x%b;
printf("%d",d);
}
printf("\n");
return 0;
}
摘自 like7xiaoben
补充:软件开发 , C++ ,