Filled Under:

C Program to Check whether a given Number is Perfect Number

C program to check whether a given number is perfect number


 C Program to Check whether a given Number is Perfect  Number

In this program, I have discussed about the C program to check whether a given number is perfect number

A number is called a perfect number if the sum of all the divisors of that number is equal to that number.
For example:- 6,,,,,,,, 1+2+3=6.

 
#include<stdio.h>
int main()
{ int n,sum=0,k,i;
printf("Enter the number:");
scanf("%d",&n);
k=n/2;
for(i=1;i<=k;i++)
{ if(n%i==0)
{ sum=sum+i;
}
}
if(n==sum)
{printf("Perfect Number !!");
}
else
printf("Not a perfect number !!");
}

Just copy and paste the program in your desired compiler (Dev C++ is more preferable) and run it.


Enjoy programming in C.

0 comments:

Post a Comment

 

Copyright 2020 Programming in C All Right Reserved