C Program to Reverse a Number using Function

C Program to Reverse a Number:

#include<stdio.h>
#include<conio.h>
void main()
{
int num, rev = 0, rem;
printf("Enter the number to reverse: ");
scanf("%d", &num);
while (num != 0){
rem = num % 10;
rev = rev * 10 + rem;
num = num/10;
}
printf("The reversed number is: %d", rev);
getch();
}

Output:
Enter the number to reverse: 71874
The reversed number is: 47817

 

C Program to Reverse a Number using Function:

#include<stdio.h>
#include<conio.h>
Reverse(int n)
{
int sum=0;
while (n!=0)
{
sum = sum*10 + n%10;
n /= 10;
}
return sum;
}
void main()
{
int rev, num;
clrscr();
printf("Enter a Positive Number: ");
scanf("%d", &num);
rev = Reverse(num);
printf("The Reverse of given number %d is: %d", num, rev);
getch();
}

 

Output:

C Program to Reverse a Number using Function