Reverse a number in C|Learnerspage

2
74
Reverse a number in C

#include <stdio.h>
#include <conio.h>
void main()
{
clrscr(); // Clean the screen
int n, reversedNumber = 0, remainder; // Initializing three variables
printf(“Enter an integer: “);
scanf(“%d”, &n); // Asking to enter a number
while(n != 0) // loop until the number n is not equal to or less than 0
{
remainder = n%10; // Calculating the remainder
reversedNumber = reversedNumber*10 + remainder;
n /= 10;
}
printf(“Reversed Number = %d”, reversedNumber); // Print out the reversed number
getch();
}

2 COMMENTS

    • Thanks for your suggestion. We will certainly try to make videos on such programming related topics and upload it to the Youtube.

LEAVE A REPLY

Please enter your comment!
Please enter your name here