Guião laboratorial n.º 0 – exercício 3

“Desenvolva uma função que conte quantas vezes surge o maior elemento num vetor de inteiros. A função recebe como argumentos o nome e a dimensão do vetor. Devolve como resultado o número de vezes que o maior elemento surge no vetor.”

#include <stdio.h>
#include <stdlib.h>

#define TAM 10

int funcao1(int v[TAM], int t){
int maior=v[0];
int total=0;
int i;

for(i=0; i<t; i++){
    if(v[i]>maior)
    {
        maior=v[i];
    }
}

for(i=0; i<t; i++){
    if(v[i]==maior)
    {
        total=total+1;
    }
}


return total;
}

int main()
{
    int vector[TAM]={0,1,25,3,4,25,20,7,8,27};
    printf("o maior vem: %d", funcao1(vector, TAM));
    return 0;
}


Tags : ,

0 thoughts on “Guião laboratorial n.º 0 – exercício 3”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.