C PROGRAM TO ACCEPT AN INTEGER AND REVERSE IT | Indian Shout

You are here: » C PROGRAM TO ACCEPT AN INTEGER AND REVERSE IT

C PROGRAM TO ACCEPT AN INTEGER AND REVERSE IT

/* Write a 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
——————————*/

ilook website
 
 

Categories:Uncategorized;Tags: , , , , , ,

   

No Comment to “C PROGRAM TO ACCEPT AN INTEGER AND REVERSE IT”

  1. No Comment yet. Be the first to comment...
Leave your comment here: