Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Escrever um
- programa que lê 2 vetores X[10] e Y[10] em um procedimento.
- Em seguida, criar:
- a) Um procedimento que receberá os dois vetores e deverá retornar ao main()
- a diferença entre X e Y;
- b) Uma função que receberá os dois vetores e deverá retornar ao main()
- a soma entre X e Y;
- c) Uma função ou procedimento que receberá os dois vetores e deverá retornar
- ao main() o produto entre X e Y.
- Exibir no main() o resultado de cada uma das operações.*/
- #include <stdio.h>
- #include <stdlib.h>
- #define MAX 3
- void DiferencaVetores(float a[], float b[], float diferenca[]);
- void SomaVetores(float a[], float b[], float soma[]);
- void ProdutoVetores(float a[], float b[], float produto[]);
- void main(){
- float a[MAX], b[MAX], soma[MAX], diferenca[MAX], produto[MAX];
- printf("Digite os vetores a[%d] e b[%d]\n",MAX,MAX);
- for(int i = 0; i<MAX; i++){
- printf("a[%d]: ",i+1);
- scanf("%f",&a[i]);
- }
- for(int i = 0; i<MAX; i++){
- printf("b[%d]: ",i+1);
- scanf("%f",&b[i]);
- }
- printf("\n---\n");
- DiferencaVetores(a, b, diferenca);
- for(int i=0; i<MAX; i++) printf("%.2f - %.2f = %.2f\n", a[i], b[i], diferenca[i]);
- printf("---\n");
- SomaVetores(a, b, soma);
- for(int i=0; i<MAX; i++) printf("%.2f + %.2f = %.2f\n", a[i], b[i], soma[i]);
- printf("---\n");
- ProdutoVetores(a,b,produto);
- for(int i=0; i<MAX; i++) printf("%.2f * %.2f = %.2f\n", a[i], b[i], produto[i]);
- printf("---\n");
- system("Pause");
- }
- void DiferencaVetores (float a[], float b[], float diferenca[]){
- for(int i=0; i<MAX; i++) diferenca[i] = a[i] - b[i];
- }
- void SomaVetores (float a[], float b[], float soma[]){
- for(int i=0; i<MAX; i++) soma[i] = a[i] + b[i];
- }
- void ProdutoVetores (float a[], float b[], float produto[]){
- for(int i=0; i<MAX; i++) produto[i] = a[i] * b[i];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement