"The best way to cheer yourself up is to try to cheer somebody else up." Mark Twain

Monday, January 18, 2010

Check Perfect No.

Factors of 6 are 1, 2, 3.

6 = 1+2+3

so, 6 is a perfect no.


#include<iostream.h>
#include<conio.h>


void main()
{
int num, r , fsum=0;
cout<< "\n Enter a number:";
cin >> num;
int n = num/2;
int i;
while(i<n)
{
if(num%i==0)
fsum = fsum + i;
i++
}
if(fsum == num)
cout<<"\n"<< num <<" is a perfect no.";
else
cout<<"\n"<< num <<" is a NOT perfect no.";getch();


}

No comments:

Post a Comment

C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do it blows your whole leg off.
Now Playing: Ballade Pour Adeline

About Me

My photo
I m an IT lecturer of a college. I love social-work. I want to do something beneficial for society before dying , that can promote our society, to some extent.