write a program to check whether it's a perfect no
Answers
Answered by
4
/*
* 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
* 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
RiyaWani:
it is a positive integer that is equal to the sum of it's proper divisors
Answered by
5
hope it helps u.........
Attachments:
Similar questions
Math,
8 months ago
Political Science,
8 months ago
Hindi,
8 months ago
Math,
1 year ago
Chemistry,
1 year ago