FREE E LEARNING PLATFORM
HOMEEXCEPTIONSOOPSJVMINTRO
 

Display Armstrong Numbers between 1 and 1000

noidatut course




An integer number is known as Armstrong number if the sum of cubes of its individual digits is equal to the number itself. Here we will write a program to display armstrong numbers upto 1000.

Example: Prints Armstrong numbers upto 1000

#include <cmath>  
using namespace std;  
int main(){
     int sum, num;
     cout<<"Armstrong numbers between 1 and 1000: ";
     for(int i = 0; i < 10; i++) {
        for(int j = 0; j < 10; j++) {
           for(int k = 0; k < 10; k++) {
              num = i * 100 + j * 10 + k;
              sum = pow(i, 3) + pow(j, 3) + pow(k, 3);
              if(num == sum)
                 cout<<num<<"  ";
           }
        }
     }
     return 0;
  }

Output

Armstrong numbers between 1 and 1000: 0 1 153 370 371 407






Leave Comment