beginnersbook.com

  • Home
  • All Tutorials
    • Learn Servlet
    • Learn JSP
    • Learn JSTL
    • Learn C
    • Learn C++
    • Learn MongoDB
    • Learn XML
    • Learn Python
    • Learn Perl
    • Learn Kotlin
  • Core Java
  • OOPs
  • Collections
  • Java I/O
  • JSON
  • DBMS

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

Enjoyed this post? Try these related posts

  1. C++ Program to check Armstrong Number
  2. C++ Program to Check whether an input number is Prime or not
  3. C++ Program to check whether the input number is Even or Odd
  4. C++ Program for Binary Search
  5. C++ Program to Add two Times entered by User
  6. C++ Program to Swap Two Numbers using Third variable

Leave a Reply Cancel reply

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

Programs

  • C Programs
  • Java Programs

Recently Added..

  • JSON Tutorial
  • Java Regular Expressions Tutorial
  • Java Enum Tutorial
  • Java Annotations Tutorial

Copyright © 2012 – 2021 BeginnersBook . Privacy Policy . Sitemap