Dremendo Tag Line

Reverse 3 digit number in C

scanf() - Question 8

In this question, we will see how to input a three digit number in C programming using the scanf() function and reverse it. To know more about scanf() function click on the scanf() function lesson.

Q8) Write a program in C to input a three digit number and reverse it.

Input: 289
Reverse: 982

Program

#include <stdio.h>
#include <conio.h>

int main()
{
    int n,fd,md,ld,rev;
    printf("Enter a three digit number\n");
    scanf("%d",&n);
    fd=n/100;
    md=(n/10)%10;
    ld=n%10;
    rev=ld*100+md*10+fd;
    printf("Reverse=%d",rev);
    return 0;
}

Output

Enter a three digit number
326
Reverse=623
video-poster