[AED] aula01 ProgA fix
This commit is contained in:
parent
26f108f8bf
commit
1194bfc81b
Binary file not shown.
|
@ -1,25 +1,16 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
int arr_length(int arr[])
|
void print_array(char s[], int arr[], int arr_size) {
|
||||||
{
|
|
||||||
int count = 0;
|
|
||||||
for(int i=0; arr[i]!='\0'; i++) {
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
return count;
|
|
||||||
}
|
|
||||||
|
|
||||||
void print_array(char s[], int arr[]) {
|
|
||||||
printf("%s:\n", s);
|
printf("%s:\n", s);
|
||||||
for (int i=0; i<arr_length(arr); i++) {
|
for (int i=0; i<arr_size; i++) {
|
||||||
printf("%d ", arr[i]);
|
printf("%d ", arr[i]);
|
||||||
}
|
}
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void cumSum(int a[], int b[]) {
|
void cumSum(int a[], int b[], int arr_size) {
|
||||||
int c = 0;
|
int c = 0;
|
||||||
for (int i=0; i<arr_length(a); i++) {
|
for (int i=0; i<arr_size; i++) {
|
||||||
c += a[i];
|
c += a[i];
|
||||||
b[i] = c;
|
b[i] = c;
|
||||||
}
|
}
|
||||||
|
@ -27,10 +18,8 @@ void cumSum(int a[], int b[]) {
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
int a[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
|
int a[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
|
||||||
print_array("a", a);
|
print_array("a", a, sizeof(a)/sizeof(*a));
|
||||||
|
int b[12] = {0};
|
||||||
int b[12] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
cumSum(a, b, sizeof(a)/sizeof(*a));
|
||||||
//print_array("b", b);
|
print_array("b", b, sizeof(b)/sizeof(*b));
|
||||||
cumSum(a, b);
|
|
||||||
print_array("b", b);
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue