-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExample5.c
39 lines (36 loc) · 915 Bytes
/
Example5.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
#include <stdio.h>
#include <stdlib.h>
//A program that selects the sum of special numbers that are divisors of themselves, excluding themselves, from a sequence and transfers them to a new sequence.
int perfect(int x) {
int i=x-1,sum=0;
while (i > 0) {
if (x%i == 0) {
sum += i;
}
i--;
}
if (sum == x) {
return x;
}
else return -1;
}
int main(int argc, char const *argv[])
{
int n=5,i,j=0,y;
// printf("How many numbers does your array consist of?\n");
// scanf("%d", &n);
int array[5], array2[5];
for (i = 0; i < n; i++) {
printf("Enter the %d. value : \n",i+1);
scanf("%d", &array[i]);
array2[i] = perfect(array[i]);
}
j = 1;
for (i = 0; i < n; i++) {
if (array2[i] != -1) {
printf("%d.value = %d\n", j, array2[i]);
j++;
}
}
return 0;
}