Dr. A.P.J. Abdul Kalam Technical University, Lucknow
KCS101 / KCS201 Programming for Problem Solving - Using C Language
Lab Exercises
18. Write a program to find the reverse of a number.
/*
File: Prgrm18.c
Author: Aditya Saini
Date: Sept 30, 2019
Description: Program to find the reverse of a number.
*/
#include <stdio.h>
int main (void)
{
int number;
int reverse_number;
int temp;
//Input number.
printf ("Input number: ");
scanf ("%d", &number);
int reverse_number;
int temp;
//Input number.
printf ("Input number: ");
scanf ("%d", &number);
//Finding the reverse number.
temp = number;
reverse_number = 0;
while (temp != 0)
{
reverse_number = reverse_number * 10 + temp % 10;
temp = temp / 10;
}
//Output the result.
printf ("Reverse number: %d", reverse_number);
reverse_number = 0;
while (temp != 0)
{
reverse_number = reverse_number * 10 + temp % 10;
temp = temp / 10;
}
//Output the result.
printf ("Reverse number: %d", reverse_number);
};
Output
Input number: 1234
Reverse number: 4321
Reverse number: 4321
No comments:
Post a Comment
Please do not post spam links.