C function that takes an integer value and returns the number with its digits reversed

Programming Example

Write a C function that takes an integer value and returns the number with its digits reversed.

Solution

#include <stdio.h>
int reverse(int);
int main()
{
    int num,rev;
    printf("Enter any Integer Number : ");
    scanf("%d",&num);
    rev=reverse(num);
    printf("Reverse Number is : %d",rev);
    return 0;
}
int reverse(int n)
{
	int r=0,d;
	while(n>0)
	{
		d=n%10;
		r=r*10+d;
		n=n/10;
	}
	return r;
}
Output

Enter any Integer Number : 5674

Reverse Number is : 4765

CCC Online Test 2021 CCC Practice Test Hindi Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level NIELIT Study material and Quiz Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Website development Company in Allahabad