Programming Examples

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


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

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

Output

Online Exam Quiz for One day Exam Online Typing Test CCC Online Test 2026 Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Best Website and Software Company in Allahabad