Users Online
· Guests Online: 135
· Members Online: 0
· Total Members: 188
· Newest Member: meenachowdary055
· Members Online: 0
· Total Members: 188
· Newest Member: meenachowdary055
Forum Threads
Newest Threads
No Threads created
Hottest Threads
No Threads created
Latest Articles
Articles Hierarchy
30 C Program to Reverse a Given Number
This C Program reverses a given number by using modulo operation.
Here is source code of the C program to reverse a given number. The C program is successfully compiled and run on a Linux system. The program output is also shown below.
/*
* C program to accept an integer and reverse it
*/
#include <stdio.h>
void main()
{
long num, reverse = 0, temp, remainder;
printf("Enter the number\n");
scanf("%ld", &num);
temp = num;
while (num > 0)
{
remainder = num % 10;
reverse = reverse * 10 + remainder;
num /= 10;
}
printf("Given number = %ld\n", temp);
printf("Its reverse is = %ld\n", reverse);
}
$ cc pgm42.c
$ a.out
Enter the number
567865
Given number = 567865
Its reverse is = 568765
Here is source code of the C program to reverse a given number. The C program is successfully compiled and run on a Linux system. The program output is also shown below.
/*
* C program to accept an integer and reverse it
*/
#include <stdio.h>
void main()
{
long num, reverse = 0, temp, remainder;
printf("Enter the number\n");
scanf("%ld", &num);
temp = num;
while (num > 0)
{
remainder = num % 10;
reverse = reverse * 10 + remainder;
num /= 10;
}
printf("Given number = %ld\n", temp);
printf("Its reverse is = %ld\n", reverse);
}
$ cc pgm42.c
$ a.out
Enter the number
567865
Given number = 567865
Its reverse is = 568765
Comments
No Comments have been Posted.
Post Comment
Please Login to Post a Comment.