Thursday, 22 December 2016

A program to print 3 armstrong numbers

Statement : A program to print 3 armstrong numbers
Code : 
// A program to print 3 armstrong numbers
#include<iostream>
using namespace std;
void main()
{
           cout << "\t\t\tArmstrong Numbers Between Interval\n\n";
              int num1, num2, i, n, b, s;
              int j = 1; //variable for printing counting
              cout << "Enter First Number: ";
              cin >> num1;
              cout << "Enter Second Number: ";
              cin >> num2;
              cout << "Armstrong Numbers Between " << num1 << " And " << num2 << " Are:- " << endl;
              for (i = num1; i <= num2; i++)
              {
                     s = 0;
                     n = i;
                     while( n>0 )
                     {
                           b = n % 10;
                           s = s + b*b*b; //will add cube of the number
                            n = n / 10;
                     }
                     if (s == i)
                     {
                           cout <<j<<". "<< i << endl;
                           j++; //for formated output
                     }
              }

       cout << "\n";
       system("pause");

}

Mohammad Tayyab

Author & Editor

Imagination is more important than knowledge.

0 comments:

Post a Comment