Write a program to reverse the given number in C language.

Tested on: Turbo C++ Version 4.0Time Complexity: O (log₁₀ n)Space Complexity: O (1)Open Source: MIT
1
2
    #include <stdio.h>
3
    #include <conio.h>
4
    void main()
5
    {
6
        int num, rem, sum = 0, temp;
7
        clrscr();
8
        printf("Enter the number:");
9
        scanf("%d", &num);
10
        temp = num;
11
        while (num != 0)
12
        {
13
            rem = num % 10;
14
            sum = sum * 10 + rem;
15
            num = num / 10;
16
        }
17
        printf("The Reverse of %d decimal digits is %d", temp, sum);
18
    }
19
        

Output

1
2
    Enter the number:5468
3
    The Reverse of 5468 decimal digits is 8645
4
     

Rate the Code

Reviews are published after a quick safety check (usually within 24 hours).

Reviews are public. Developers can see basic device specifications to respond. Learn more

How to run reverse the given number program in C-Language?

To run reverse the given number program in C-Language, follow the below mentioned steps:

  1. Copy the Code: Press the copy button in the code block to copy the complete code.
  2. Open Turbo C++ Version 4: Open the Turbo C++ (Version 4) software on your system.
  3. Paste the code: Paste the copied code into Turbo C++’s editor.
  4. Compile the Code: Compile the program by pressing the Alt+F9 keys. This shows you the errors and warnings, if any.
  5. Run the code: Press the Ctrl+F9 keys to run the program if the program is successfully compiled.
  6. Enter the Input: Provide the required inputs or your desired inputs, if applicable.
  7. Receive the Result: Get the result of the program on the screen based on the provided inputs.

More about Reversing a Number Using the C Language

Aim: To reverse the user-provided input number. For example: User input 123, then the output will be 321.

Concepts used in this program

  • While Loop: To process all the digits of the user input.
  • Modulus Operator (%): To get the last digit of the number.
  • Integer Division (/): To remove the last digit of the number.
  • Multiplication: To add the next digit by multiplying by 10. Because in the number system, 10 is the base.
  • Temporary Variable (temp): To keep the user input unchanged and showing in the output as original number.

Real-life Applications

  • To check a palindrome: This reverse number algorithm is used to find out whether the number is a palindrome or not.
  • Improve Logic Building: To improve the logic building of students or beginners to explain the loop and modulus concepts.
License: This program's source code is open-sourced under the MIT License, while the rest of the program's text content and overall dhimanp platform and brand content remain proprietary under dhimanp.

Submit your modified code

Your submissions are published after a quick safety check (usually within 7 days).

Submissions are public. Developers can see basic device specifications to respond. Learn more

Disclaimer

The information that you shared with us will be publicly visible, and everyone can see your information. And we (dhimanp) are not responsible if anyone misuses this information. We can remove any submitted code at any time for better transparency.

Privacy Policy

If you share your data with us by submitting your code for credit, then we may show your full name, school or college name, and city name on our website.

We are not using this data to track you and are not selling this data to anyone.

If you want to remove your name from our website, you can contact us, and we will remove your name from our website. In the removal process, full credit, including your full name, school or college, city, and code, will be removed from our website.