Guest User

Untitled

a guest
Apr 24th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. void imprimeVetor(int *vetor, int TAM)
  4. {
  5. for (int indice = 0; indice < TAM; indice++)
  6. {
  7. if (indice == 0)
  8. {
  9. printf("[%i,", *(vetor + indice));
  10. }
  11.  
  12. else if (indice == (TAM - 1))
  13. {
  14. printf("%i]", *(vetor + indice));
  15. }
  16.  
  17. else
  18. {
  19. printf("%i,", *(vetor + indice));
  20. }
  21. }
  22. }
  23.  
  24. int *somaVetor (int *vetor, int *vetor_2)
  25. {
  26. int vetor_res[2];
  27.  
  28. for (int indice = 0; indice < 2; indice++)
  29. {
  30. vetor_res[indice] = *vetor + *vetor_2;
  31.  
  32. vetor++;
  33. vetor_2++;
  34. }
  35.  
  36. return &vetor_res[0];
  37. }
  38.  
  39. int main()
  40. {
  41. int TAM = 2, *vetor_res;
  42. int v1[TAM], v2[TAM];
  43.  
  44. for (int indice = 0; indice < TAM; indice++)
  45. {
  46. printf("ELEMENTO %i: ",indice + 1);
  47. scanf("%i", &v1[indice]);
  48. }
  49.  
  50. for (int indice = 0; indice < TAM; indice++)
  51. {
  52. printf("ELEMENTO %i: ",indice + 1);
  53. scanf("%i", &v1[indice]);
  54. }
  55.  
  56. imprimeVetor(&v1[0], TAM);
  57.  
  58. vetor_res = somaVetor(&v1[0], &v2[0]);
  59.  
  60. imprimeVetor(vetor_res, TAM);
  61.  
  62. return 0;
  63. }
Add Comment
Please, Sign In to add comment