有问题就有答案
Q1:thousand=num/1000%10; %10是什么意思?假如这个数是8842,结果会是什么?
除以10,余数是8。
Q2:thousand=num/1000%10; 假如这个数是8842,结果会是什么?
%10 是 除以10 求余 结果是8
Q3:C语言中将一个四位数的千位和个位对调
思路:分别得到这个四位数的千位、百位、十位、个位,结果等于个位*1000+百位*100+十位*10+千位代码为:#includeint main(){ int num = 2568; int thousand = num /1000; int hundred = num%1000/100; int ten = num%1000%100/10; int one = num%100%100%10; printf("原数字为:%d,转换后为:%d\n", num,one*1000+hundred*100+ten*10+thousand);} 运行结果:
Q4:C语言简单问题
#includemain(){ long num; int indiv,ten,hundred,thousand,ten_thousand,place; printf("Please input an integer:"); scanf("%ld",#); if(num>9999) place=5; else if(num>999) place=4; else if(num>99) place=3; else if(num>9) place=2; else place=1; printf("place=%d\n",place); printf("each digit is:"); ten_thousand=num/10000; thousand=(int)(num-ten_thousand*10000)/1000; hundred=(int)(num-ten_thousand*10000-thousand*1000)/100; ten=(int)(num-ten_thousand*10000-thousand*1000-hundred*100)/10; indiv=(int)(num-ten_thousand*10000-thousand*1000-hundred*100-ten*10); switch(place) { case 5: printf("%d,%d,%d,%d,%d",ten_thousand,thousand,hundred,ten,indiv); printf("\nReverse list is:"); printf("%d,%d,%d,%d,%d",indiv,ten,hundred,thousand,ten_thousand); break; case 4: printf("%d,%d,%d,%d",thousand,hundred,ten,indiv); printf("\nReverse list is:"); printf("%d,%d,%d,%d,%d",indiv,ten,hundred,thousand); break; case 3: printf("%d,%d,%d",hundred,ten,indiv); printf("\nReverse list is:"); printf("%d,%d,%d",indiv,ten,hundred); break; case 2: printf("%d,%d",ten,indiv); printf("\nReverse list is:"); printf("%d,%d",indiv,ten); break; case 1: printf("%d",indiv); printf("\nReverse list is:"); printf("%d",indiv); break; }}
Q5:在C语言环境下输入一个四位整数,求对应的数字并输出,最后千位和十位互换,百位
# include in change(int s){ int a,b,c,d,I;int ch[4];a=(int)(s/1000);b=(int)(s/100);c=(int)(s/100);d=(int)(s000);\ *分隔输入数字的每个位,并分别将其分配给ABCD * \ ch[0]=c;ch[1]=d;ch[2]=a;ch[3]=b;\ *更改每个位上数字的顺序,并将它们存储在数组ch*\ s=0中;for(I=0;i4;I )\*此循环将分离位上的数字组合成一个完整的四位数* \ { s *=10s=ch[I];}返回s;\ *返回结果* \ } void main(){ int in;printf("请输入数字\ n ");scanf("%d ",in;);printf("您的答案是\ n ");printf("%d\n ",change(in));}/*该程序经过调试可以使用,得到正确的结果*/
Q6:C语言问题
# include " iostream。h " int reverse(int);void main(){ printf(" 1234的反转是:%d\n ",反转(1234));} int reverse(int n) { int k=0,j;而(n0){ j=n;n=n/10;k=k * 10j}返回k;}