Wednesday, 25 May 2016



Write a program that inputs a number form the user and display all perfect number upto the number entered.

          #include<iostream.h>
          #include <conio.h>
          void main()
          {
                 int  num , mid, sum, limit;
                 clrscr();
                 cout<<"Enter the number upto which perfect numbers are required. ";
                 cin>>limit;
                 if(limit < 6)
                    cout<<"No perfect number upto " <<limit;
                 else
                 {
                     cout<<"Perfect numbers upto "<<limit<< "  are "<<endl;
                     for(num = 6; num <= limit; num++)
                     {
                         sum = 0;
                          mid = num / 2;
                          for(int i=1; i<= mid; i++)
                          {
                               if((num % i)== 0)
                                   sum += i;
                          }
                          if(sum == num)
                             cout<<num << " ";
                     }
                 }
                  getch();
          }


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();
           }