adsense

Hii, welcome to my site. My name is Om prakash kartik. This blog helps you to learn programming languages concepts.

program in c to check a number is perfect or not using function

Program in C to check a number is perfect or not using function



#include<stdio.h>
#include<conio.h>
 int perfect(int n);
 int main()
  {
   int a,p;
   printf("Enter a number:-");
   scanf("%d",&a);
   p=perfect(a);
   if(p==a)
    printf("%d is perfect no.",a);
 else
    printf("%d is not perfect no.",a);
    getch();
  }
  int perfect(int n)
   {
     int sum=0,i;
     for(i=1;i<n;i++)
      {
       if(n%i==0)
        {
          sum+=i;
   }
     }
     return (sum);
   }
Output:-





Post a Comment

0 Comments