Write a C Program to find the Reverse of a Number
/*Using While Loop*/
#include <stdio.h>
void main()
{
int n, r = 0;
printf("Please enter a number: ");
scanf("%d",&n);
while (n > 0)
{
r = r * 10;
r = r + n%10;
n = n/10;
}
printf("Reversed number is = %d: ", r);
}
/*Using For Loop*/
#include <stdio.h>
void main()
{
int n, r;
printf("Please enter a number: ");
scanf("%d",&n);
for(r=0;n>0;n=n/10)
{
r = r * 10;
r = r + n%10;
}
printf("Reversed number is = %d: ", r);
}
Comments
Post a Comment