Write a C program to find the whether a number is perfect or not using function

#include<stdio.h>
unsigned int perfect(int i);
int main()
{
    int n,i,x;
    printf("enter the number to check \n");
    scanf("%d",&n);
    x=perfect(n);
    if(x==n)
    printf("the number %d is perfect\n",n);
    else
    printf("the number %d is not perfect\n",n);
return 0;
}
unsigned int perfect(int n)
{
int i,x=0;
    for(i=1;i<=(n/2);i++)
if(n%i==0)
    x=i+x;
return x;
}

Post a Comment

0 Comments