Question 03 of 03

Armstrong Number and Reverse of a Number using While Loop

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).

C++
#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