Write a C program to Check whether a given number is perfect number or not
Program:-
#include<stdio.h>
int main()
{
int i, num, sum = 0;
printf(“\nEnter a number : “);
scanf(“%d”, &num);
for(i=1; i<num; i++)
{
if(num%i == 0)
{
sum += 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;
}
int main()
{
int i, num, sum = 0;
printf(“\nEnter a number : “);
scanf(“%d”, &num);
for(i=1; i<num; i++)
{
if(num%i == 0)
{
sum += 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;
}
Output:-
....
0 comments:
Post a Comment