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();

}

 

Related Posts

  • 82
    Problem Statement: If a four-digit number is input through the keyboard, write a program to obtain the sum of the first and last digit of this number. Solution: /* Sum of 1st and last digit of a four digit number */ #include<stdio.h> #include<conio.h> main() { int n,a,sum=0; clrscr(); printf("\Enter a…
    Tags: digit, number, program, write, learn, example, tutorial, basic
  • 74
    Problem Statement :  Two numbers are input through the keyboard into two locations C and D. Write a program to interchange the contents of C and D. Answer: /* Interchanging of contents of two variables c & d */ #include<stdio.h> #include<conio.h> main() { int c,d,e; clrscr(); printf("\n Enter the number…
    Tags: printf, number, write, #include, program, int, example, basic, tutorial, learn
  • 68
    Problem Statement: Write a program to calculate the salary as per the following table: Solution: /* C program to calculate salary */ main( ) { char g ; int yos, qual, sal ; printf ( "Enter Gender, Years of Service and Qualifications ( 0 = G, 1 = PG ):" )…
    Tags: program, example, write, learn, tutorial, basic
  • 63
    Write a C Program for the following :- Ramesh’s basic salary is input through the keyboard. His dearness allowance is 40% of basic salary, and house rent allowance is 20% of basic salary. Write a program to calculate his gross salary. Answer:  /* To Calculate the gross salary of Ramesh…
    Tags: basic, printf, program, write, #include, tutorial, learn, example
  • 61
    Problem Statement: Temperature of a city in Fahrenheit degrees is input through the keyboard. Write a c program to convert this temperature into Centigrade degrees. Answer: /* Conversion of Temperature from Fahrenheit to Centigrade */ #include <stdio.h> #include <conio.h> main() { float fr, cent; clrscr(); print("\n Enter the temperature in…
    Tags: program, printf, #include, write, example, tutorial, learn, basic

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

Your email address will not be published. Required fields are marked *

%d bloggers like this: