你说的第二题在“c程序设计(第二版)”一书中, 有一个专门的例子说到,你有时间就去看看吧!
盖茨来电话,他跟我说了一大串的英语。我真的不知道到底说了什么!!我长叹了一声:你还是说C语言吧!
#include <stdio.h>
main()
{
int i,a,b,c,d,e;
scanf("%d",&i);
if ((i>=100000)||(i<0)) printf("Out!");
else
{
if ( ( a = i / 10000 ) > 1 )
{
b=(i-a*10000)/1000;
c=(i-a*10000-b*1000)/100;
d=(i-a*10000-b*1000-c*100)/10;
e=i-a*10000-b*1000-c*100-d*10;
printf("这是一个五位数!");
printf("%d%d%d%d%d ",a,b,c,d,e);
printf("%d%d%d%d%d",e,d,c,b,a);
}
}
}
这个是个5位数,怎么可以随便就定义为INT型要知道,65535是小于99999的呵呵
main()
{
int i,b5[5],b4[4],b3[3],b2[2];
int b1;
long a,c;
printf("input a number:\n");
scanf("%ld",&a);
if(a>99999||a<0) printf("the number is error!\n");
else if(a>9999)
{ printf("the number is 5 bit.\n");
for(i=0;i<5;i++)
{c=a;
a=a%10;
b5[i]=a;
a=c/10;
}
printf("the reverse sequence is:\n");
for(i=0;i<5;i++)
printf("%4d",b5[i]);
printf("\n");
printf("the normal sequence is:\n");
for(i=5;i!=0;i--)
printf("%4d",b5[i-1]);
printf("\n");
}
else if(a>999)
{ printf("the number is 4 bit.\n");
for(i=0;i<4;i++)
{c=a;
a=a%10;
b4[i]=a;
a=c/10;
}
printf("the reverse sequence is:\n");
for(i=0;i<4;i++)
printf("%4d",b4[i]);
printf("\n");
printf("the normal sequence is:\n");
for(i=4;i!=0;i--)
printf("%4d",b4[i-1]);
printf("\n");
}
else if(a>99)
{ printf("the number is 3 bit.\n");
for(i=0;i<3;i++)
{c=a;
a=a%10;
b3[i]=a;
a=c/10;
}
printf("the reverse sequence is:\n");
for(i=0;i<3;i++)
printf("%4d",b3[i]);
printf("\n");
printf("the normal sequence is:\n");
for(i=3;i!=0;i--)
printf("%4d",b3[i-1]);
printf("\n");
}
else if(a>9)
{ printf("the number is 2 bit.\n");
for(i=0;i<2;i++)
{c=a;
a=a%10;
b2[i]=a;
a=c/10;
}
printf("the reverse sequence is:\n");
for(i=0;i<2;i++)
printf("%4d",b2[i]);
printf("\n");
printf("the normal sequence is:\n");
for(i=2;i!=0;i--)
printf("%4d",b2[i-1]);
printf("\n");
}
else
{ printf("the number is 1 bit.\n");
b1=a;
printf("the reverse sequence is:\n");
printf("%d",b1);
printf("\n");
printf("the normal sequence is:\n");
printf("%d",b1);
printf("\n");
}
}
这个已经运行成功!试试!