10
Jul.2008
输入一个不多于五位的正整数,判断它是几位数,分别打印出各位数字,并按逆序打印各位数字。
#include
using namespace std;
int main()
{ void function(int a);
int input,flag;
cout<<"pls input the number! no more than 5 bits"<
cin>>input;
if(input>=0 && input<=9) flag=1; //根据输入数据大小,判定位数
if(input>=10 && input<=99) flag=2;
if(input>=100 && input<=999) flag=3;
if(input>=1000 && input<=9999) flag=4;
if(input>=10000 && input<=99999) flag=5;
cout<<"this number is "<
function(input); //调用函数function()
cout<
return 0; }
void function(int a)
{ int tmp[5]; //将输入数的各位分别存贮
tmp[4]=a/10000;
tmp[3]=(a%10000)/1000;
tmp[2]=(a%1000)/100;
tmp[1]=(a%100)/10;
tmp[0]=a%10;
int i,j,icount;
cout<<"the number of each bits is"<
for(i=4;i>=0;i--)
{ if(tmp[i]!=0) //如果数据不足5位,判断多余的几位,使其不输出
{ icount=i; //记录空位的个数
break; }
}
for(i;i>=0;i--) //按位输出
cout<
cout<
for(j=0;j<=icount;j++) //反向输出各位,到空位时停止输出
cout<
}
#include
using namespace std;
int main()
{ void function(int a);
int input,flag;
cout<<"pls input the number! no more than 5 bits"<
cin>>input;
if(input>=0 && input<=9) flag=1; //根据输入数据大小,判定位数
if(input>=10 && input<=99) flag=2;
if(input>=100 && input<=999) flag=3;
if(input>=1000 && input<=9999) flag=4;
if(input>=10000 && input<=99999) flag=5;
cout<<"this number is "<
function(input); //调用函数function()
cout<
return 0; }
void function(int a)
{ int tmp[5]; //将输入数的各位分别存贮
tmp[4]=a/10000;
tmp[3]=(a%10000)/1000;
tmp[2]=(a%1000)/100;
tmp[1]=(a%100)/10;
tmp[0]=a%10;
int i,j,icount;
cout<<"the number of each bits is"<
for(i=4;i>=0;i--)
{ if(tmp[i]!=0) //如果数据不足5位,判断多余的几位,使其不输出
{ icount=i; //记录空位的个数
break; }
}
for(i;i>=0;i--) //按位输出
cout<
cout<
for(j=0;j<=icount;j++) //反向输出各位,到空位时停止输出
cout<
}
作者:菜鸟学编程@Bo-Blog
地址:http://www.node-net.org/read.php?16
版权所有©转载时必须以链接形式注明作者和原始出处及本声明!














输入四个整数,要求按由小
输入三个数(int,fl


