Write a program to reverse a given number in C?

#include
#include
main()
{
int n, reverse=0, rem; //declaration of variables.
clrscr(); // It clears the screen.
printf(“Enter a number: “);
scanf(“%d”, &n);
while(n!=0)
{
rem=n%10;
reverse=reverse*10+rem;
n/=10;
}
printf(“Reversed Number: %d”,reverse);
getch(); // It reads a character from the keyword.
}

Certainly! Here’s a simple program in C to reverse a given number:

c
#include <stdio.h>

int main() {
int number, reversedNumber = 0, remainder;

printf("Enter an integer: ");
scanf("%d", &number);

while (number != 0) {
remainder = number % 10;
reversedNumber = reversedNumber * 10 + remainder;
number /= 10;
}

printf("Reversed number: %d\n", reversedNumber);

return 0;
}

This program takes an integer input from the user, then iteratively divides the number by 10 to extract the last digit (remainder) and builds the reversed number by multiplying the existing reversed number by 10 and adding the remainder. This process continues until the original number becomes 0. Finally, it prints the reversed number.