C Programming

Solved Example

Practice Questions

Exercise Question

Reverse a 3 digit number

Objective

Input a 3 digit number and find the reverse of the number.

Program / Solution:

#include<stdio.h>
int main() {
	int n;
	int first_dig,second_dig,third_dig,rev;
	printf("Enter a 3 digit number: ");
	scanf("%d",&n);
	
	first_dig = n % 10;
	second_dig = (n / 10) % 10;
	third_dig = (n / 100) % 10;
	
	rev = first_dig * 100 + second_dig * 10 + third_dig;
	
	printf("Reverse number = %d",rev);
	
	return 0;
}

Sample Output:

Enter a 3 digit number: 254
Reverse number = 452