谁能给我这个程序的干输出?

标签 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/

相关文章:

c - 为什么打印数组时会出现额外的字符

c - 程序没有显示错误,但无法编译。你能帮我解决我需要做的事情吗

c - 就地替换字符串中的字符

c - Emacs 在 switch 语句后缩进 break

c - 数学运算?

c - scanf 跳过扫描字符

c++ - 安装 pHash 库时对 `fftw_init_threads' 的 undefined reference

c - C 中的指针及其值

c - 函数类似于 C 中的宏

c - 除法结果始终为零