We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 80dd25b commit c5e8c7cCopy full SHA for c5e8c7c
1 file changed
programs/C/perfe.c
@@ -0,0 +1,18 @@
1
+#include<stdio.h>
2
+
3
+int main()
4
+ {
5
+ int sum = 0, n;
6
+ //prompt user for number to check whether it is perfect or not
7
+ printf("please enter number to check whether it is perfect or not:");
8
+ scanf("%d", &n);
9
+ for( int i = 1; i <= n/2; i++){
10
+ if( n%i == 0) //find sum of divisors of entered number
11
+ sum += i;
12
+ }
13
+ //check if sum of divisors is equal to entered number or not and then print required output
14
+ if( sum == n)
15
+ printf("hurray!,entered number is perfect\n");
16
+ else
17
+ printf("number is not perfect, try another one\n");
18
0 commit comments