• 0
Sign in to follow this  
Guilherme C. Silva

Problema com Vetores

Question

Meu codigo multiplica vetorA por vetorB até 4 de indice ele multiplica certinho porem se eu botar 2 vetores de 5 se multiplicando o [0] x [0] da errado a multiplicação.
 

#include<stdio.h>

int main () {
	int Indice,i,Xvalor;
	int VetA[Indice];
	int VetB[Indice];
	int VetC[Indice];
	
	printf("Quantos indices desejas nos vetores?\n");
	scanf("%d",&Xvalor);
	Indice = Xvalor - 1;

	for (i=0;i<=Indice;i++){
		printf("Digite um numero para o indice:%d do VetorA. \n",i);
		scanf("%d", &VetA[i]);
	}
	
	for (i=0;i<=Indice;i++){
		printf("Digite um numero para o indice:%d do VetorB. \n",i);
		scanf("%d", &VetB[i]);
	}
		
	for(i=0;i<=Indice;i++){
		VetC[i]= VetA[i] * VetB[i];
	}
	
	for(i=0;i<=Indice;i++){
		printf("VetC[%d]=%d\n",i,VetC[i]);
	}
	}

 

Resposta para vetorA[4]=1,2,3,4 e VetorB[4]=1,2,3,4

VetC[0]=1
VetC[1]=4
VetC[2]=9
VetC[3]=16

Resposta para vetorA[6]=1,2,3,4,5,6 e VetorB[6]=1,2,3,4,5,6

VetC[0]=5      //????
VetC[1]=12    //????
VetC[2]=9
VetC[3]=16
VetC[4]=25
VetC[5]=36

Edited by Guilherme C. Silva

Share this post


Link to post
Share on other sites

1 answer to this question

Recommended Posts

  • 0

resolvido! 

...

int Indice,i,Xvalor;

	printf("Quantos indices desejas nos vetores?\n");
	scanf("%d",&Xvalor);
	Indice = Xvalor - 1;
int VetA[Indice];
int VetB[Indice];
int VetC[Indice];
  

 

Edited by Guilherme C. Silva

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this