Skip to content

Instantly share code, notes, and snippets.

@muhammedfurkan
Created December 26, 2020 21:40
Show Gist options
  • Save muhammedfurkan/6ed980ae608bf370cee5271c562e634e to your computer and use it in GitHub Desktop.
Save muhammedfurkan/6ed980ae608bf370cee5271c562e634e to your computer and use it in GitHub Desktop.
check input number is perfect number ?
#include <stdio.h>
int isperfect(int input)
{
int sum = 0, value = input / 2;
do
{
if (input % value == 0)
sum += value;
value--;
} while (value);
if (input == sum)
return 1;
else
return 0;
}
int main()
{
unsigned long long number;
printf("Enter any number: ");
scanf("%llu", &number);
int j;
j = number + 10;
printf("entered number is %d\n", number);
for (number; number < j; number++)
{
if (isperfect(number) == 1)
{
printf("%d is it perfect\n", number);
}
else if (isperfect(number) == 0)
{
printf("%d is not perfect\n", number);
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment