Monday, 10 November 2014

Write a program to find Perfect numbers?

Leave a Comment
 /*  Programmed by http://cppexamples.blogspot.com
                   https://www.facebook.com/cppexamples*/

#include"iostream"
#include"iomanip"
using namespace std;
void main()              
{
    system("color 0A");
   int i=1, j=1,temp=0;
   double range;
   cout<<"Enter the range till you want to find the perfect number: ";
   cin>>range;
   system("cls()");
   while(i<=range)
   {
       while(j<=range)
       {                         
           if(j<i)
           {
               if(i%j==0 )
                   temp+=j;
           }                        
           j++;
       }                          
       if(temp==i)
       {
           cout<<setw(25)<<i<<endl;
       }
       i++;
       j=1;  temp=0;
   }
   cout<<setw(18)<<"These are the perfect numbers b/w 1 to "<<range<<endl;
   system("pause");
 }
If You Enjoyed This, Take 5 Seconds To Share It