Cycle 03
Control Structures, Decision Making & Loops
Armstrong Number and Reverse of a Number using While Loop
Problem Statement
Write a Turbo C++ program to input an integer number, reverse its digits using a while loop, and check whether the original number is an Armstrong number (sum of cubes of its digits equals the number).
#include <iostream.h>
#include <conio.h>
void main() {
int num, temp, digit, reverse = 0, sumOfCubes = 0;
clrscr();
cout << "Enter an integer number: ";
cin >> num;
temp = num;
while (temp > 0) {
digit = temp % 10;
reverse = (reverse * 10) + digit;
sumOfCubes = sumOfCubes + (digit * digit * digit);
temp = temp / 10;
}
cout << "\n--- Results ---" << endl;
cout << "Original Number : " << num << endl;
cout << "Reversed Number : " << reverse << endl;
if (sumOfCubes == num) {
cout << num << " is an ARMSTRONG NUMBER (Sum of cubes: " << sumOfCubes << ")" << endl;
} else {
cout << num << " is NOT an Armstrong number (Sum of cubes: " << sumOfCubes << ")" << endl;
}
getch();
}
Question 3 of 3