Friday, 31 May 2013
Do you like this story?
C program to check a number is perfect number or not
A number which is equal to the sum of its divisor is called perfect number.For eg,divisors of 6 are 1,2 and 3.The sum of these divisors is 6.So 6 is called as perfect number.
#include<stdio.h>
#include<conio.h>
//perfect number checking
void main()
{
int n,d,sum;
clrscr();
printf("\n Enter the number : ");
scanf("%d",&n);
sum = 0;
d = 1;
while ( d<= n/2)
{
if ( n % d == 0 )
{
sum = sum + d;
}
d++;
}
if ( sum == n )
printf("\n %d is perfect number",n);
else
printf("\n %d is not perfect number",n);
}
and the output is like:
A number which is equal to the sum of its divisor is called perfect number.For eg,divisors of 6 are 1,2 and 3.The sum of these divisors is 6.So 6 is called as perfect number.
#include<stdio.h>
#include<conio.h>
//perfect number checking
void main()
{
int n,d,sum;
clrscr();
printf("\n Enter the number : ");
scanf("%d",&n);
sum = 0;
d = 1;
while ( d<= n/2)
{
if ( n % d == 0 )
{
sum = sum + d;
}
d++;
}
if ( sum == n )
printf("\n %d is perfect number",n);
else
printf("\n %d is not perfect number",n);
}
and the output is like:
This post was written by: Franklin Manuel
Franklin Manuel is a professional blogger, web designer and front end web developer. Follow him on Twitter
Subscribe to:
Post Comments (Atom)
0 Responses to “ ”
Post a Comment