-2
Good afternoon, basically I am trying to make a program that will ask the user to enter 10 numbers between 1 and 100 and with a menu in which the menu will have 5 options at this time I am in option 3 where I wanted when I clicked on option 3 the program would take vector 2 and present-if the odd numbers and then the even numbers, but for some reason he is entering Random values when I will present the numbers.
#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
main(){
int i;
int b;
int c;
int d;
int e;
int vetor1[10];
int vetor2[10];
int vetor3[10];
int vetorpar[10];
int vetorimpar[10];
int soma = 0;
int perg = 1;
int media;
setlocale(LC_ALL,"");
for(i = 0 ; i < 10 ; i++){ //introdução de 10 valores
printf("\nEscreva um numero de 1 a 100 : ");
scanf("%i", &vetor1[i]);
}
for(b = 0; b < 10 ; b++){ //Armazenar o vetor1 no vetor2 e ver se são impares ou pares os numeros
vetor2[b] = vetor1[b];
if(vetor2[b] % 2 != 0)
{
vetorimpar[b] = vetor2[b];
}
else{
vetorpar[b] = vetor2[b];
}
}
while(perg != 0)
{
printf("\n---------------------------------------------------------");
printf("\n 0 - Sair\n 1 - Soma\n 2 - Inversa do Vetor\n 3 - Numeros impares e Pares\n 4 - Arroz\n 5 - Rand\n Digite a opção desejada : ");
scanf("%i", &perg);
printf("\n---------------------------------------------------------");
switch (perg){
case 0:
printf("\n Obrigado pela sua escolha, volte sempre.\n\n");
system("pause");
break;
case 1:
soma = vetor1[0] + vetor1[1] + vetor1[2] + vetor1[3] + vetor1[4] + vetor1[5] + vetor1[6] + vetor1[7] + vetor1[8] + vetor1[9]; //soma de todos os valores do vetor1
media = soma / 10; //media da soma dos valores do vetor1
printf("\n A media é : %i", media);
break;
case 2:
for(c = 9; c >= 0 ; c--){
printf("\nOrdem inversa : %i", vetor2[c]); //inverso dos valores do vetor1
}
break;
case 3:
for(d = 0 ; d < 10 ; d++){
if(vetorpar[d] != NULL){
printf("\nval par : %i", vetorpar[d]); //apresentação dos valores pares do vetor2
}
else{
printf("\nval par : %i", vetorimpar[d]); //apresentação dos valores impares do vetor2
}
}
break;
case 4:
printf("");
break;
case 5:
printf("");
break;
default :
printf("");
}
}
}
Show code and say it has problems without specifying what problems are these usually result in stackoverflow team alert.
– RHER WOLF
tries to formulate your question a little better, it’s really complicated to interpret what you have as doubt.
– Paulo.Fritsch
As the even and odd quantity can be different use different indexes for
vetorimpar
andvetorpar
starting from 0 and only increasing when finding an odd or a pair.– anonimo
OK thanks for the help but I’ve managed to do it myself, maybe I misspelled yes, but the interpretation of the code is not so complicated basically the code will ask the user numbers between 1 and 100 and the user will enter these numbers 10 times after the code will provide 5 options and the user will have to choose one of the options 1 option makes the media the second does vector 2 inversion and the third was supposed to write the odd numbers first and then the pairs and what was happening I was trying to put even numbers in another array and odd numbers in another array
– Dimas Hutsulyak
and then I just wanted to present with a cycle for the two arrays but I wasn’t giving because the array was assuming Random values for some reason and was displaying numbers that were not supposed to appear or if the even numbers were 2 4 6 8 10 it also presented numbers Random and it was 31231231, 2 , 2898328432, 4, 28927323 ,8, 12318231, 10
– Dimas Hutsulyak
basically what I changed was the cycles so it looks like this :
– Dimas Hutsulyak