Skip to content

Commit 4434274

Browse files
committed
updated my code #71
1 parent 80dd25b commit 4434274

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

programs/C/perfe.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include<stdio.h>
2+
3+
int main()
4+
{
5+
int sum = 0, n;
6+
//prompting 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+
{
11+
if( n%i == 0){ //finding sum of divisors of entered number
12+
sum += i;
13+
}
14+
}//checking if sum of divisors is equal to entered number or not and then printing required output
15+
if( sum == n){
16+
printf("hurray!,entered number is perfect\n");
17+
}else
18+
printf("number is not perfect, try another one\n");
19+
}

0 commit comments

Comments
 (0)