From 217be624354cd332f3410229df2bc5eed34faaaf Mon Sep 17 00:00:00 2001 From: archit kaushal Date: Tue, 23 Oct 2018 16:46:22 +0530 Subject: [PATCH] added updated c program to check for perfect numbers #71 --- programs/C/per.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 programs/C/per.c diff --git a/programs/C/per.c b/programs/C/per.c new file mode 100644 index 0000000..5a77cae --- /dev/null +++ b/programs/C/per.c @@ -0,0 +1,20 @@ +#include + +int main() +{ + int sum = 0, n; + //prompting user for number to check whether it is perfect or not + printf("please enter number to check whether it is perfect or not:"); + scanf("%d", &n); + for( int i = 1; i <= n/2; i++) + { + if(n%i==0){ //finding sum of divisors of entered number + sum += i; + } + }//checking if sum of divisors is equal to entered number or not and then printing required output + if( sum == n) + { + printf("hurray!,entered number is perfect\n"); + }else + printf("number is not perfect, try another one\n"); + } \ No newline at end of file