Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- void vetorSoma(float *v1, float *v2, int tam);
- void vetorDiferenca(float *v1, float *v2, int tam);
- void vetorProduto(float *v1, float *v2, int tam);
- float buscaMaior(float *v1, float *v2, int tam, float *menor);
- float somaElementos(float *v1, float *v2, int tam, float *produto);
- int main()
- {
- int i, tam, op;
- float *v1,*v2, maior, menor, soma, produto=1;
- printf("\nInforme o tamanho do vetor: \n");
- scanf("%d", &tam);
- v1=(float*)malloc(tam*sizeof(float));
- v2=(float*)malloc(tam*sizeof(float));
- if(v1==NULL && v2==NULL)
- {
- printf("\nImpossível alocar memória\n");
- }
- printf("\n\nLeitura vetor 1: \n\n");
- for(i=0; i<tam; i++)
- {
- printf("\n\nv1 [%d]: ", i);
- scanf("%f", v1+i);
- }
- printf("\nLeitura vetor 2: \n\n");
- for(i=0; i<tam; i++)
- {
- printf("\n\nv1 [%d]: ", i);
- scanf("%f", v2+i);
- }
- printf("\nImpressão do vetor v1 : \n");
- for(i=0; i<tam; i++);
- {
- printf("%f", *(v1+i));
- }
- printf("\nImpressão do vetor v2: \n");
- for(i=0; i<tam; i++);
- {
- printf("%f", *(v2+i));
- }
- do
- {
- printf("\n\n1-Vetor Soma \n2-Vetor Diferença \n3-Vetor Produto \n4-Maior Elemento de v1 e Menor Elemeno de v2 \n5-Soma entre os Elementos de v1 e Produto entre os Elementos de v2 \n6-Sair \n\nOpção:");
- scanf("%f", &op);
- switch(op)
- {
- case 1:
- vetorSoma(v1,v2,tam);
- break;
- case 2:
- vetorDiferenca(v1,v2,tam);
- break;
- case 3:
- vetorProduto(v1,v2,tam);
- break;
- case 4:
- maior=buscaMaior(v1,v2,tam, &menor);
- printf("\n\nMaior elemento: %f", maior);
- printf("\n\nMenor elemento: %f", menor);
- break;
- case 5:
- soma=somaElementos(v1,v2,tam, &produto);
- printf("\nSoma entre os elementos de v1: %f", soma);
- printf("\nProduto elementos de v2: %f", produto);
- break;
- case 6:
- printf("\n\nObrigado\n\n");
- break;
- default:
- printf("\n\nInformação inválida\n\n");
- }
- }while(op!=6);
- free(v1);
- free(v2);
- }
- void vetorSoma(float *v1, float *v2, int tam)
- {
- int i;
- float v3[tam];
- for(i=0; i<tam; i++)
- {
- *(v3+i)=*(v1+i)+*(v2+i);
- }
- printf("\n\nVetor Soma: \n");
- for(i=0; i<tam; i++)
- {
- printf("%f\t", *(v3+i));
- }
- }
- void vetorDiferenca(float *v1, float *v2, int tam)
- {
- int i;
- float v3[tam];
- for(i=0; i<tam; i++)
- {
- *(v3+i)=*(v1+i)-*(v2+i);
- }
- printf("\n\nVetor Diferença: \n");
- for(i=0; i<tam; i++)
- {
- printf("%f\t", *(v3+i));
- }
- }
- void vetorProduto(float *v1, float *v2, int tam)
- {
- int i;
- float v3[tam];
- for(i=0; i<tam; i++)
- {
- *(v3+i)=*(v1+i)**(v2+i);
- }
- printf("\n\nVetor Produto: \n");
- for(i=0; i<tam; i++)
- {
- printf("%f\t", *(v3+i));
- }
- }
- float buscaMaior(float *v1, float *v2, int tam, float *menor)
- {
- int i;
- float maior;
- maior=*v1;
- for(i=0; i<tam; i++)
- {
- if(*(v1+i)>maior)
- {
- maior=*(v1+i);
- }
- }
- *menor=*v2;
- for(i=0; i<tam; i++)
- {
- if(*(v2+i)<*menor)
- {
- *menor=*(v2+i);
- }
- }
- return maior;
- }
- float somaElementos(float *v1, float *v2, int tam,float *produto)
- {
- int i;
- float soma=0;
- for(i=0; i<tam; i++)
- {
- soma+=*(v1+i);
- }
- for(i=0; i<tam; i++)
- {
- *produto=*produto**(v2+i);
- }
- return(soma);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement