- #1
Dili
- 13
- 0
I need to write a program to check whether a number is perfect
eg: 6=1+2+3 , 28=1+2+4+7+14
i wrote one, but it doesn't work. also I've seen programs written with different preprocessors, we are required to write it on stdio.h and math.h
#include<stdio.h>
#include<math.h>
int main()
{
int a,b,c,d,i;
scanf("%d",&a);
{
for(i=1;i<a;i++)
b=a%i;
if(b==0)
{
c=0;
c=c+i;
}
if(c==a)
printf("perfect\n");
}
return 1;
}
eg: 6=1+2+3 , 28=1+2+4+7+14
i wrote one, but it doesn't work. also I've seen programs written with different preprocessors, we are required to write it on stdio.h and math.h
#include<stdio.h>
#include<math.h>
int main()
{
int a,b,c,d,i;
scanf("%d",&a);
{
for(i=1;i<a;i++)
b=a%i;
if(b==0)
{
c=0;
c=c+i;
}
if(c==a)
printf("perfect\n");
}
return 1;
}