Factors of 6 are 1, 2, 3.
6 = 1+2+3
so, 6 is a perfect no.
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();
}
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