Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Escreve um subprograma que receba como parâmetro um vetor de inteiros
- e retorne, simultaneamente, o índice do maior elemento e o índice do menor
- elemento do vetor. */
- #include <stdio.h>
- #include <stdlib.h>
- #define MAX 5
- void AnalisaVetor(int a[], int *maior, int *menor);
- void main(){
- int a[MAX], maior, menor;
- printf("Digite um 5 numeros e entregarei o indice do maior e do menor numero\n");
- for(int i=0; i<MAX; i++){
- scanf("%d", &a[i]);
- }
- AnalisaVetor(a, &maior, &menor);
- printf("\nIndice do maior: %d\n", maior);
- printf("Indice do menor: %d\n", menor);
- system("Pause");
- }
- void AnalisaVetor(int a[], int *maior, int *menor){
- *maior = 0;
- *menor = 0;
- for(int i=1; i<MAX; i++){
- if(a[i]> a[*maior]) *maior = i;
- if(a[i]< a[*menor]) *menor = i;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement