A PLATFORM TO LEARN | CODE | ACHIEVE
" Programming is the real test of your creativity,its all about how you turn ideas into codes. "
Connect :
Code
#include<stdio.h>
int main()
{
int n,i;
int rem=0,rev=0;
int num=0;
printf("ENTER THE NUMBER ");
scanf("%d",&n;);
num=n;
while(num>0)
{
rem=num%10;
rev=rev*10+rem;
num=num/10;
}
printf("THE REVERSE OF %d IS : %d",n,rev);
return 0;
}
Output
ENTER THE NUMBER 43252
THE REVERSE OF : 25234
What we did - Our Approach
In this problem we have to find the reverse of a number.To do so we declare a variable 'rev',which will store the result value(don't forget to initialize it with zero).
Let us consider an example :
Suppose we have to find the reverse of 235,we require three steps which needs to be performed under while loop condition (while n>0).
1 : Finding Remainder : rem=num%10
So, rem=235%10=5
2 : Finding Reverse : rev=rev*10+rem
So, rev=0+5
3 : Updating number : num=num/10;
So, num=23
But num>0, so we will perform above steps until 'num' gets equal to zero.After the last iteration we find rev=532.
See this code in :
Also see :
Participate in our MONTHLY CHALLENGE,and get a chance to get listed on our site and win the TITLE of "MR.GEEK".
Join us :
Connect :
INTERESTING READ FOR YOU :
SHARE:
For any Queries,suggestions,feel free to Mail us at :
[email protected]
For reporting any kind of copyright voilation,mail us at : [email protected]
© copyright CODE OF GEEKS 2018