Write a program in c which will check a number perfect or not
#include<conio.h>
#include<stdio.h>
main()
{
int num,i=1,sum=0,j;
printf("\n\tIT'S A PROGRAM TO CHACK A NUMBER PERFECT OR NOT");
printf("\n\nEnter the number:");
scanf("%d",&num);
while(i<num)
{
for(j=1;j<=i;j++)
if(num%i==0)
sum=sum+i;
i++;
}
if(sum==num)
{
printf("\n%d is a perfect number\n",num);
}
else
{
printf("\n%d is not a perfect number\n",num);
}
return 0;
}
#include<conio.h>
#include<stdio.h>
main()
{
int num,i=1,sum=0,j;
printf("\n\tIT'S A PROGRAM TO CHACK A NUMBER PERFECT OR NOT");
printf("\n\nEnter the number:");
scanf("%d",&num);
while(i<num)
{
for(j=1;j<=i;j++)
if(num%i==0)
sum=sum+i;
i++;
}
if(sum==num)
{
printf("\n%d is a perfect number\n",num);
}
else
{
printf("\n%d is not a perfect number\n",num);
}
return 0;
}
No comments:
Post a Comment