write a program for parfect number
Answers
Answered by
0
write a program for perfect number
Answered by
1
This C Program checks whether a given number is perfect number. Perfect number is a number which is equal to sum of its divisor. For eg,divisors of 6 are 1,2 and 3. The sum of these divisors is 6. So 6 is called as perfect number.
Here is source code of the C Program to check whether a given number is perfect number. The C program is successfully compiled and run on a Linux system. The program output is in below.
/*
* C Program to Check whether a given Number is Perfect Number
*/
#include <stdio.h>
int main()
{
int number, rem, sum = 0, i;
printf("Enter a Number\n");
scanf("%d", &number);
for (i = 1; i <= (number - 1); i++)
{
rem = number % i;
if (rem == 0)
{
sum = sum + i;
}
}
if (sum == number)
printf("Entered Number is perfect number");
else
printf("Entered Number is not a perfect number");
return 0;
}
Output: $ cc pgm42.c $ a.out Enter a Number 6 Entered Number is perfect number $ a.out Enter a Number 100 Entered Number is not a perfect number.
hope it helps you...
Here is source code of the C Program to check whether a given number is perfect number. The C program is successfully compiled and run on a Linux system. The program output is in below.
/*
* C Program to Check whether a given Number is Perfect Number
*/
#include <stdio.h>
int main()
{
int number, rem, sum = 0, i;
printf("Enter a Number\n");
scanf("%d", &number);
for (i = 1; i <= (number - 1); i++)
{
rem = number % i;
if (rem == 0)
{
sum = sum + i;
}
}
if (sum == number)
printf("Entered Number is perfect number");
else
printf("Entered Number is not a perfect number");
return 0;
}
Output: $ cc pgm42.c $ a.out Enter a Number 6 Entered Number is perfect number $ a.out Enter a Number 100 Entered Number is not a perfect number.
hope it helps you...
Similar questions