Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- void imprimeVetor(int *vetor, int TAM)
- {
- for (int indice = 0; indice < TAM; indice++)
- {
- if (indice == 0)
- {
- printf("[%i,", *(vetor + indice));
- }
- else if (indice == (TAM - 1))
- {
- printf("%i]", *(vetor + indice));
- }
- else
- {
- printf("%i,", *(vetor + indice));
- }
- }
- }
- int *somaVetor (int *vetor, int *vetor_2)
- {
- int vetor_res[2];
- for (int indice = 0; indice < 2; indice++)
- {
- vetor_res[indice] = *vetor + *vetor_2;
- vetor++;
- vetor_2++;
- }
- return &vetor_res[0];
- }
- int main()
- {
- int TAM = 2, *vetor_res;
- int v1[TAM], v2[TAM];
- for (int indice = 0; indice < TAM; indice++)
- {
- printf("ELEMENTO %i: ",indice + 1);
- scanf("%i", &v1[indice]);
- }
- for (int indice = 0; indice < TAM; indice++)
- {
- printf("ELEMENTO %i: ",indice + 1);
- scanf("%i", &v1[indice]);
- }
- imprimeVetor(&v1[0], TAM);
- vetor_res = somaVetor(&v1[0], &v2[0]);
- imprimeVetor(vetor_res, TAM);
- return 0;
- }
Add Comment
Please, Sign In to add comment