-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram28.c
64 lines (48 loc) · 856 Bytes
/
Program28.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
52
53
54
55
56
57
58
59
60
61
62
63
64
//Write a program to add the factors of the input
#include<stdio.h>
#include<stdbool.h>
int SumFactors(int iNo)
{
int iCnt = 0;
int iSum = 0;
if(iNo < 0) //updater
{
iNo = -iNo;
}
for(iCnt =1; iCnt <= (iNo/2); iCnt++)
{
if((iNo % iCnt) == 0)
{
iSum = iSum + iCnt;
}
}
return iSum;
}
bool CheckPerfect(int iNumber)
{
int iResult = 0;
iResult = SumFactors(iNumber);
if(iResult == iNumber)
{
return true;
}
else{
return false;
}
}
int main()
{
int iValue = 0;
bool bRet = false;
printf("Enter number: \n");
scanf("%d",&iValue);
bRet = CheckPerfect(iValue);
if(bRet == true)
{
printf("%d is perfect number \n",iValue);
}
else{
printf("%d is not a perfect number",iValue);
}
return 0;
}