谁可以给我这个程序的干输出?
#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();
}
Run Code Online (Sandbox Code Playgroud)
假设从干输出你的意思是代码的解释,这是我的尝试.
假设用户输入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 )
Run Code Online (Sandbox Code Playgroud)
所以价值b印在屏幕上
3
现在
c = a / 10 ; // 143 / 10 = 14
a = c ; // so now a = 14
Run Code Online (Sandbox Code Playgroud)
再一次,我们回到了 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 )
Run Code Online (Sandbox Code Playgroud)
因此,价值b已印在屏幕上,已有3
34
现在
c = a / 10 ; // 14 / 10 = 1
a = c ; // so now a = 1
Run Code Online (Sandbox Code Playgroud)
再次,我们回到了 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 )
Run Code Online (Sandbox Code Playgroud)
所以b在已有的屏幕上打印的价值34
341
现在
c = a / 10 ; // 1 / 10 = 0
a = c ; // so now a = 0
Run Code Online (Sandbox Code Playgroud)
我们回到了 while()
while( a != 0 ) // a = 0 therefor condition is FALSE and the block of
// code inside the loop is NOT executed.
Run Code Online (Sandbox Code Playgroud)
希望它有所帮助.
注意
而不是
c=a/10;
a=c;
Run Code Online (Sandbox Code Playgroud)
你可以简单地写
a /= 10
Run Code Online (Sandbox Code Playgroud)
其次,
int a,b,c,d,e;
Run Code Online (Sandbox Code Playgroud)
目的是e什么?