-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path200-215.c.c
99 lines (90 loc) · 1.28 KB
/
200-215.c.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include<stdio.h>
#include<math.h>
int sum(int a[],int size) //200
{
int i,sum_a=0;
for(i=0;i<size;i++)
{if(a[i]>0)
sum_a=sum_a+a[i];
}
return sum_a;
}
// 202
int TimChuSoDauLe(int n)
{
int donvi;
n = abs(n);
while(n >= 10)
{
donvi = n % 10;
n /= 10;
}
if(n % 2 == 0)
{
return 0;
}
return 1;
}
int TinhTongCacSoChuSoDauLe(int a[], int n)
{
int i;
int Tong = 0;
for( i = 0; i < n; i++)
{
if(TimChuSoDauLe(a[i]) == 1)
{
Tong += a[i];
}
}
return Tong;}
//203
int chuso_chuc_5(int n)
{
n = abs(n);
n = n / 10;
int hangchuc = n % 10;
if(hangchuc == 5)
{
return 1;
}
return 0;}
int sum_5(int a[],int n)
{
int i,sum;
for(i=0;i<n;i++)
{
if(chuso_chuc_5(a[i])==1)
{
sum+=a[i];
}
}
return sum;
}
int tongcuctri(int a[],int n)
{
int i,sum;
for(i=0;i<n;i++)
{
if(i==0&&a[i]!=a[i+1])
sum+=a[i];
else if(i==n-1&&a[i]!=a[i-1])
sum+=a[i];
else if()
}
}
int main()
{
int i,j;
int a[9]={2,51,436,155,52,42,-532,52,5};
int n=sizeof(a)/sizeof(a[0]);
for(i=0;i<9;i++)
{
printf("%d ",a[i]);
}
int tong = sum(a,9);
printf("\nSum:%d\n",tong);
int TongDauLe = TinhTongCacSoChuSoDauLe(a, n);
printf("\nTong cac phan tu co chu so dau la le: %d", TongDauLe);
printf("\nTong chu so chuc la 5:%d",sum_5(a,n));
return 0;
}