C program to accept an integer and reverse it

by Nideesh C on April 12, 2011 · 0 comments

in C Programming




/* C program to accept an integer and reverse it */

#include <stdio.h>

void main()
{
long  num, rev = 0, temp, digit;

printf(“Enter the number\n”);  /*For better programming,choose ‘long int’ */
scanf(“%ld”, &num);

temp = num;

while(num > 0)
{
digit = num % 10;
rev = rev * 10 + digit;
num /= 10;
}

printf(“Given number   = %ld\n”, temp);
printf(“Its reverse is = %ld\n”, rev);
}

/* —————————
Output
Enter the number
123456
Given number   = 123456
Its reverse is = 654321
——————————*/

Not Satisfied ? Just search & get the result

Related Posts Plugin for WordPress, Blogger...
Be Sociable, Share!

Related posts:

  1. C program to reverse a given integer number and check whether it is a palindrome. Output the given numbers with suitable message
  2. Sample – Program to enter an integer and print its total value based on the formula ‘x – 1/3!x3 + 1/5!x5 – 1/7!x7 + 1/9!x9′.
  3. C program to check whether a given number is prime or not and output the given number with suitable message
  4. C program to convert the given binary number into decimal
  5. C program to check whether a given integer number is positive or negative

Leave a Comment

Previous post:

Next post: