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

Similar Posts:

 
 
Posted by 0 Responses

Categories:PREPARATION MATERIALS;Tags: , , , , , ,

Free Email Newsletter

Stay Updates with this Blog. Get Free email newsletter updates..

And then confirm your email subcription

   

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:

 
Search
Free Email Updates
Get All Latest Updates in Ur e-mail Inbox..

And then confirm your email subcription

Free SMS Alerts
Sponsored Links
Copy Protected by Chetans WP-Copyprotect.