Skip to content

Commit

Permalink
added updated c program to check for perfect numbers pclubuiet#71
Browse files Browse the repository at this point in the history
  • Loading branch information
archu5 committed Oct 23, 2018
1 parent 80dd25b commit a922160
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
20 changes: 20 additions & 0 deletions programs/C/per.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include<stdio.h>

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");
}
26 changes: 26 additions & 0 deletions programs/C/perf.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include<stdio.h>

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);
//finding sum of divisors of entered number
for(int i=1;i<=n/2;i++)
{
if(n%i==0)
{
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");


}

0 comments on commit a922160

Please sign in to comment.