BeginnersBook

  • Home
  • Java
    • Java OOPs
    • Java Collections
    • Java Examples
  • C
    • C Examples
  • C++
    • C++ Examples
  • DBMS
  • Computer Network
  • Python
    • Python Examples
  • More…
    • jQuery
    • Kotlin
    • WordPress
    • SEO
    • JSON
    • JSP
    • JSTL
    • Servlet
    • MongoDB
    • XML
    • Perl

C++ Program to display Armstrong Numbers between 1 and 1000

By Chaitanya Singh | Filed Under: C++ Programs

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, if you are looking for a program to check armstrong number then refer: C++ program to check whether input number is armstrong or not.

Example: Prints Armstrong numbers upto 1000

This program prints the armstrong numbers between 1 and 100. To understand this program you should have the knowledge of nested for loop.

#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 a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Programs

  • C Programs
  • Java Programs
  • C++ Programs

Copyright © 2012 – 2022 BeginnersBook . Privacy Policy . Sitemap