Answers for "Write a C++ program using for loop to find whether the number is an Armstrong number or not."

C++
3

armstrong number

sum of cubes of the digits
Posted by: Guest on November-02-2020
0

Write a C++ program using for loop to find whether the number is an Armstrong number or not.

#include <iostream>
using namespace std;

int main() {
    int num, originalNum, remainder, result = 0;
    cout << "Enter a three-digit integer: ";
    cin >> num;
    originalNum = num;

    while (originalNum != 0) {
        // remainder contains the last digit
        remainder = originalNum % 10;
        
        result += remainder * remainder * remainder;
        
        // removing last digit from the orignal number
        originalNum /= 10;
    }

    if (result == num)
        cout << num << " is an Armstrong number.";
    else
        cout << num << " is not an Armstrong number.";

    return 0;
}
Posted by: Guest on December-25-2020

Code answers related to "Write a C++ program using for loop to find whether the number is an Armstrong number or not."

Browse Popular Code Answers by Language