2023-09-17 23:37:44 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2023-09-22 11:10:38 +00:00
|
|
|
void print_array(char s[], int arr[], int arr_size) {
|
2023-09-17 23:37:44 +00:00
|
|
|
printf("%s:\n", s);
|
2023-09-22 11:10:38 +00:00
|
|
|
for (int i=0; i<arr_size; i++) {
|
2023-09-17 23:37:44 +00:00
|
|
|
printf("%d ", arr[i]);
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
2023-09-22 11:10:38 +00:00
|
|
|
void cumSum(int a[], int b[], int arr_size) {
|
2023-09-17 23:37:44 +00:00
|
|
|
int c = 0;
|
2023-09-22 11:10:38 +00:00
|
|
|
for (int i=0; i<arr_size; i++) {
|
2023-09-17 23:37:44 +00:00
|
|
|
c += a[i];
|
|
|
|
b[i] = c;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
int a[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
|
2023-09-22 11:10:38 +00:00
|
|
|
print_array("a", a, sizeof(a)/sizeof(*a));
|
|
|
|
int b[12] = {0};
|
|
|
|
cumSum(a, b, sizeof(a)/sizeof(*a));
|
|
|
|
print_array("b", b, sizeof(b)/sizeof(*b));
|
2023-09-17 23:37:44 +00:00
|
|
|
}
|