Wednesday, 25 May 2016

Write a program that input a number from the user and display all Armstrong numbers upto the number entered. 

           #include<iostream.h>
           #include<conio.h>
           int main()
           {
                 int num, n, sum, r , limit;
                 clrscr();
                 cout<<"Enter the number upto which armstrong numbers are required. ";
                 cin>> limit;
                 cout<<"Armstrong number upto "<<limit<<" are "<<endl;
                 for(num = 1; num <= limit; num++)
                 {
                         n = num;
                         sum = 0;
                         while (n != 0)
                         {
                               r = n % 10;
                               sum += r * r * r;
                                n /= 10;
                          }
                          if(sum == num)
                          cout<<num<< " ";
                 }
                  getch();
           }

No comments:

Post a Comment