forked from srinirad/IA2-Test1-Session2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp4final.c
53 lines (53 loc) · 869 Bytes
/
p4final.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
#include <stdio.h>
int input_array_size()
{
int n;
printf("enter array size\n");
scanf("%d",&n);
return n;
}
void input_array(int n, int a[n])
{
printf("enter the composite numbers\n");
for(int i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
}
int is_composite(int n)
{
int i,composite;
for(i=2;i<n/2;i++)
{
if(n%i==0)
{
composite=1;
}
}
return composite;
}
int sum_composite_numbers(int n,int a[n])
{
int sum=0;
for(int i=1;i<n;i++)
{ if(is_composite(a[i]))
{
sum=sum+a[i];
}
}
return sum;
}
void out_put(int sum)
{
printf("sum is %d",sum);
}
int main()
{
int n,sum;
n=input_array_size();
int a[n];
input_array(n,a);
sum=sum_composite_numbers(n,a);
out_put(sum);
return 0;
}