In: Computer Science
(Please solve the question using C Language. Thanks). Write a function called is_perfect which takes an integer n and returns 1 if n is a perfect number, otherwise it will return 0. If the sum of a number’s proper divisors are equal to the number, than the number is called a perfect number. For example, 6 is a perfect number: 6=1+2+3.
// Screenshot of the code
// Sample output
// Code to copy
/*C program to check nunber is perfect or not.*/
#include <stdio.h>
/*function to check perfect number or not*/
int is_perfect(int num)
{
int loop,sum=0;
for(loop=1; loop<num; loop++)
{
if(num%loop==0)
sum+=loop;
}
if(sum==num)
return 1; /*Perfect Number*/
else
return 0; /*Not Perfect Number*/
}
int main()
{
int num,loop;
int sum;
printf("Enter an integer number: ");
scanf("%d",&num);
if(is_perfect(num))
printf("%d is a perfect number.",num);
else
printf("%d is not a perfect number.",num);
return 0;
}