Suppose we are considering Digit 234. We have output 43
#include<stdio.h>
#include<conio.h>
main()
{
int num, rem, reverse=0;
clrscr();
printf(" Enter any number you want to be reverse :- ");
scanf("%d"",&num);
while(num!=0)
{
rem=num%10;
reverse=reverse*10+rem;
num=num/10;
}
printf(" Reverse Of given number is :- %d ",reverse);
getch();
}
O/p : Enter any number you want to be reverse :- 234
Reverse Of given number is :- 432
Execution :
num =234 , reverse =0
while( 234!=0)
{
rem= num%10; rem= 234%10 ; rem=4
reverse=reverse*10+rem; reverse=0*10+4; reverse=4
num=num/10; num=234/10 num=23
}
while(num!=23)
{
rem= num%10; rem= 23%10 ; rem=3
reverse=reverse*10+rem; reverse=4*10+3; reverse=43
num=num/10; num=234/10 num=2
}
while(num!=2)
{
rem= num%10; rem= 2%10 ; rem=2
reverse=reverse*10+rem; reverse=43*10+2; reverse=432
num=num/10; num=234/10 num=0
}
while(num!=0)---> condition is false.
0 comments:
Post a Comment