75: Write a program to print the reverse of a given number using a while loop
// 21. Write a program to print the reverse of a given number using a while loop
// **************************************************************************************************
#include <iostream>
using namespace std;
int main()
{
int num, numf = 0, a = 0;
cout << "Enter a number: ";
cin >> num;
int b = num;
while (num > 0)
{
a = num % 10; // getting last digit of num
numf = numf * 10 + a; // * by 10 adds a zero to which a is added
num = num / 10; // removing last digit of num
}
cout << "The reverse of " << b << " is: " << numf;
return 0;
}
Comments
Post a Comment