write a C program to reverse the number

c program to reverse digit
c program to reverse digit

Problem Statement :

If a five-digit number is input through the keyboard, write a program to reverse the number.

Answer:

/* To reverse the digits of 5-digit number */

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

main()
{

int n,a,b;
long int revnum=0;

clrscr();
printf(“\n Enter a five digit number less than 32767”);
scanf(“%d”,&n);

a=n%10; /*last digit */
n-n/10; /* remaining digit */
revnum=revnum+a*1000;
a=n%10; /*3rd digit */
n-n/10; /* remaining digit */
revnum=revnum+a*100;

a=n%10; /*2nd digit */
n-n/10; /* remaining digit */
revnum=revnum+a*10;

a=n%10; /*1st digit */
revnum=revnum+a;

printf(“\n The reverse number is %ld”, revnum);

printf(“\n\n\n\n\n Press any key to exit…”);
getch();

}

 

Satya Prakash

VOIP Expert: More than 8 years of experience in Asterisk Development and Call Center operation Management. Unique Combination of Skill Set as IT, Analytics and operation management.

Leave a Reply