Wap to check a number whether it is a perfect number or not
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int n,sum=0,i=1;
cout<<"enter no.";
cin>>n;
while(i<n)
{
if(n%i==0)
sum+=i;
i++;
}
if(sum==n)
cout<<"perfect";
else
cout<<"not perfect";
getch();
}
*****************
OUTPUT
enter no. 4
perfect
*****************
No comments:
Post a Comment