Advertisement
Drowze

APC B 02 - Funções 04

Aug 26th, 2014
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.79 KB | None | 0 0
  1.  /*Escrever um
  2. programa que lê 2 vetores X[10] e Y[10] em um procedimento.
  3. Em seguida, criar:
  4. a) Um procedimento que receberá os dois vetores e deverá retornar ao main()
  5. a diferença entre X e Y;
  6. b) Uma função que receberá os dois vetores e deverá retornar ao main()
  7. a soma entre X e Y;
  8. c) Uma função ou procedimento que receberá os dois vetores e deverá retornar
  9. ao main() o produto entre X e Y.
  10. Exibir no main() o resultado de cada uma das operações.*/
  11.  
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #define MAX 3
  15.  
  16. void DiferencaVetores(float a[], float b[], float diferenca[]);
  17. void SomaVetores(float a[], float b[], float soma[]);
  18. void ProdutoVetores(float a[], float b[], float produto[]);
  19.  
  20.  
  21. void main(){
  22.     float a[MAX], b[MAX], soma[MAX], diferenca[MAX], produto[MAX];
  23.     printf("Digite os vetores a[%d] e b[%d]\n",MAX,MAX);
  24.  
  25.     for(int i = 0; i<MAX; i++){
  26.         printf("a[%d]: ",i+1);
  27.         scanf("%f",&a[i]);
  28.     }
  29.  
  30.     for(int i = 0; i<MAX; i++){
  31.         printf("b[%d]: ",i+1);
  32.         scanf("%f",&b[i]);
  33.     }
  34.    
  35.     printf("\n---\n");
  36.  
  37.     DiferencaVetores(a, b, diferenca);
  38.     for(int i=0; i<MAX; i++) printf("%.2f - %.2f = %.2f\n", a[i], b[i], diferenca[i]);
  39.     printf("---\n");
  40.  
  41.     SomaVetores(a, b, soma);
  42.     for(int i=0; i<MAX; i++) printf("%.2f + %.2f = %.2f\n", a[i], b[i], soma[i]);
  43.     printf("---\n");
  44.  
  45.     ProdutoVetores(a,b,produto);
  46.     for(int i=0; i<MAX; i++) printf("%.2f * %.2f = %.2f\n", a[i], b[i], produto[i]);
  47.     printf("---\n");
  48.  
  49.     system("Pause");
  50. }
  51.  
  52. void DiferencaVetores (float a[], float b[], float diferenca[]){
  53.     for(int i=0; i<MAX; i++) diferenca[i] = a[i] - b[i];
  54. }
  55.  
  56. void SomaVetores (float a[], float b[], float soma[]){
  57.     for(int i=0; i<MAX; i++) soma[i] = a[i] + b[i];
  58. }
  59.  
  60. void ProdutoVetores (float a[], float b[], float produto[]){
  61.     for(int i=0; i<MAX; i++) produto[i] = a[i] * b[i];
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement