<分区>
任何人都可以给我这个程序的干输出吗?
#include <stdio.h>
main()
{
int a,b,c,d,e;
printf("Enter the Number to Find it's Reverse\n");
scanf("%d",&a);
while(a!=0)
{
b=a%10;
c=a/10;
printf("%d",b);
a=c;
}
getchar();
}
标签 c
<分区>
任何人都可以给我这个程序的干输出吗?
#include <stdio.h>
main()
{
int a,b,c,d,e;
printf("Enter the Number to Find it's Reverse\n");
scanf("%d",&a);
while(a!=0)
{
b=a%10;
c=a/10;
printf("%d",b);
a=c;
}
getchar();
}
最佳答案
假设从干输出中你指的是对代码的解释,这是我的尝试。
假设用户输入 143
。所以现在 a = 143
。
while( a != 0 ) // a = 143 therefor condition is true and the block of
// code inside the loop is executed.
b = a % 10 ; // 143 % 10 ( The remainder is 3 )
所以 b
的值被打印在屏幕上
3
现在
c = a / 10 ; // 143 / 10 = 14
a = c ; // so now a = 14
我们再次回到while()
while( a != 0 ) // a = 14 therefor condition is true and the block of
// code inside the loop is executed.
b = a % 10 ; // 14 % 10 ( The remainder is 4 )
所以 b
的值打印在屏幕上,屏幕上已经有 3
34
现在
c = a / 10 ; // 14 / 10 = 1
a = c ; // so now a = 1
再次,我们返回到 while()
while( a != 0 ) // a = 1 therefor condition is true and the block of
// code inside the loop is executed.
b = a % 10 ; // 1 % 10 ( its output will be 1 )
所以 b
的值打印在已经有 34
341
现在
c = a / 10 ; // 1 / 10 = 0
a = c ; // so now a = 0
我们回到while()
while( a != 0 ) // a = 0 therefor condition is FALSE and the block of
// code inside the loop is NOT executed.
希望对您有所帮助。
注意
而不是
c=a/10;
a=c;
你可以简单地写
a /= 10
其次,
int a,b,c,d,e;
e
的用途是什么?
关于谁能给我这个程序的干输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3536779/