Digital जीवन

Free Online Education for India...

Full width home advertisement

Computer Basic

C Programming

Engineering Graphics

Post Page Advertisement [Top]

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);

               //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);

               return 0;
};

Output

Input number: 1234
Reverse number: 4321



No comments:

Post a Comment

Please do not post spam links.

Bottom Ad [Post Page]

| Designed by Colorlib