-
Notifications
You must be signed in to change notification settings - Fork 0
/
EDA_ex6.c
59 lines (45 loc) · 1.02 KB
/
EDA_ex6.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
#include <stdlib.h>
#include <stdio.h>
int *soma_vetores(int *, int *, int );
int main(){
int *vet1, *vet2, *p, n;
scanf("%d", &n);
if(!(vet1 = (int*)(malloc(sizeof(int)*n)))){
printf("ERRO AO ALOCAR");
return EXIT_FAILURE;
}
int cont;
for(cont = 0; cont < n; cont++){
scanf("%d", &vet1[cont]);
}
if(!(vet2 = (int*)(malloc(sizeof(int)*n)))){
printf("ERRO AO ALOCAR ");
return EXIT_FAILURE;
}
for(cont = 0; cont < n; cont++){
scanf("%d", &vet2[cont]);
}
if(!(p = (int*)(malloc(sizeof(int)*n)))){
printf("ERRO AO ALOCAR ");
return EXIT_FAILURE;
}
p = soma_vetores(vet1,vet2,n);
for(cont = 0; cont < n; cont++){
printf("%d ", p[cont]);
}
free(vet1);
free(vet2);
free(p);
printf("\n");
return 0;
}
int *soma_vetores(int *vet1, int *vet2, int tam){
int *vetf, cont;
if(!(vetf = (int*)(malloc(sizeof(int)*tam)))){
printf("ERRO AO ALOCAR ");
}
for(cont = 0; cont < tam; cont++){
vetf[cont] = vet1[cont] + vet2[cont];
}
return vetf;
}