-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfor_lab.c
51 lines (44 loc) · 1.08 KB
/
for_lab.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <stdio.h>
int checkPerfect(int n1);
void PerfectNumbers(int stLimit, int enLimit);
int main()
{
int stLimit, enLimit;
printf("\n\n Function : perfect numbers in a given range :\n");
printf("--------------------------------------------------\n");
printf(" Input lowest search limit of perfect numbers : ");
scanf("%d", &stLimit);
printf(" Input highest search limit of perfect numbers : ");
scanf("%d", &enLimit);
printf("\n The perfect numbers between %d to %d are : \n", stLimit, enLimit);
PerfectNumbers(stLimit, enLimit);
printf("\n\n");
return 0;
}
int checkPerfect(int n1)
{
int i, sum;
sum = 0;
for(i=1; i<n1; i++)
{
if(n1 % i == 0)
{
sum += i;
}
}
if(sum == n1)
return 1;
else
return 0;
}
void PerfectNumbers(int stLimit, int enLimit)
{
while(stLimit <= enLimit)
{
if(checkPerfect(stLimit))
{
printf(" %d ", stLimit);
}
stLimit++;
}
}