9 Mar 2013

perfect_number








/*
 program to check whether a given no. is a ""perfect no."" or not.


a perfect number is a positive integer that is equal to the sum of its proper positive divisors, that is, the sum of its positive divisors excluding the number itself


The first perfect number is 6

*/




#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,c,s=0;
cout<<"Enter the number:";
cin>>a;
cout<<"The factors of "<<a<<" are as follows:"<<endl;
for(b=1;b<a;b++)
{
a%b;
if(a%b==0)
{cout<<b<<endl;
s+=b;
}
}
if(s==a)
cout<<a<<" is  a perfect number.";
else
cout<<a<<" is not a perfect number.";
getch();
}

Categories: ,

0 comments:

Post a Comment

Copyright © UPgradeCODING | Powered by Blogger