Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int main()
- {
- int array[5], valor, maiorValor = -1, posMaiorValor;
- bool teste = 1;
- for(int i = 0; i < 5; i++) //Preenchendo o vetor.
- array[i] = 0;
- for(int j = 0; j < 5; j++)
- {
- printf("Digite o %d valor >>> ",j+1);
- scanf("%d",&valor);
- for(int i = 0; i < 5; i++) //Percorre o vetor para fazer o teste.
- {
- if(valor == array[i] || valor <= 0) //Testa se o valor é diferente e maior que zero.
- {
- teste = 0;
- j--;
- printf("ERRO!!! Este valor ja existe ou e menor ou igual a 0.\n");
- break;
- }
- if(valor > maiorValor) //Pega o maior valor e a posição no vetor em que ele se encontra.
- {
- maiorValor = valor;
- posMaiorValor = j;
- }
- }
- if(teste) //Se existir um valor igual ou menor que 0 no vetor, o valor não será atribuído.
- array[j] = valor;
- else
- teste = 1;
- }
- printf("O maior valor digitado foi %d\n",maiorValor);
- printf("Sua posicao e %d",posMaiorValor+1);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement