Reverse Number in C
Q. Write a C program for Reverse Number.
#include <stdio.h>
#include <conio.h>
void main()
{
int n, sum = 0;
clrscr();
printf("Enter the number: ");
scanf("%d", &n);
while (n > 0)
{
sum = sum * 10 + n%10;
n = n/10;
}
printf("Reverse of number is :%d", sum);
getch();
}
Q. Write an algorithm to Reverse Number.
1. Start 2. Initialize an integer variable `sum` to 0. This will hold the reversed number. 3. Read the input integer `n`. 4. While `n` is greater than 0, do the following: - Extract the last digit of `n` by computing `n % 10`. - Update `sum` by multiplying the current `sum` by 10 and adding the extracted digit. - Remove the last digit from `n` by dividing `n` by 10. 5. When `n` becomes 0, all digits have been processed. 6. Print the value of `sum`, which now contains the reversed number. 7. End
Quickly Find What You Are Looking For
OnlineTpoint is a website that is meant to offer basic knowledge, practice and learning materials. Though all the examples have been tested and verified, we cannot ensure the correctness or completeness of all the information on our website. All contents published on this website are subject to copyright and are owned by OnlineTpoint. By using this website, you agree that you have read and understood our Terms of Use, Cookie Policy and Privacy Policy.
point.com