反转一个数字 [英] Reverse a number
本文介绍了反转一个数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Que - 如果通过键盘输入一个五位数字,请编写一个程序来反转该数字。
Que- If a five digit number is input through the keyboard, write a program to reverse the number.
展开 | 选择 | Wrap | 行号
推荐答案
Que - 如果通过键盘输入一个五位数,请编写一个程序反转这个数字。
void main()
{
int num = 12345,res = 0,rem;
clrscr();
while(num> 0)
{
rem = num%10;
res = res * 10 + rem;
num = num / 10;
}
printf(" Reverse of a number =%d" res);
getch();
}
根据我的逻辑是礼仪,但结果出来是不正确的...检查我们的,,,&回复
Que- If a five digit number is input through the keyboard, write a program to reverse the number.
void main()
{
int num=12345, res=0, rem;
clrscr();
while(num > 0)
{
rem=num% 10;
res=res* 10 + rem;
num=num/10;
}
printf("Reverse of a number=%d",res);
getch();
}
According to me logic is rite, but the result coming out to be is not correct... Check it our,,, & reply
它应该(并且确实)有效。
It should (and does) work.
如果我们输入最多四位数的数字,答案就是仪式,假设我输入1234答案是4321.
但如果我们输入五位数麻木,假设12345,答案不会来54321.
如果我们声明num为长,即便如此o / p对于5位数字来说不正确。
If we enter the number upto four digit,answer is rite, Suppose I enter 1234 Answer is 4321.
But If we enter five digit numb,suppose 12345, Answer is not coming 54321.
If we declare num as long, even then the o/p is not coming out to be correct for 5 digit number.
我很怀疑你,但是我将你的代码复制并粘贴到编辑器中并编译它,它产生了所需的输出。
Far be it from me to doubt you, but I copied and pasted your code into an editor and compiled it, and it produced the desired output.
这篇关于反转一个数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文