Jump to content

Calcular maior valor linha matriz


Guest João Antunes

Recommended Posts

Como posso tirar o valor mais alto de cada atleta? e trocar a media do atleta pela media dos tempos 1 dos tempos 2 . . . 

#include <stdio.h>

#define MAX_ATLETAS 3
#define MAX_REGISTOS_TEMPO 5


void inserirTempos(float tabelaTempos[][MAX_REGISTOS_TEMPO]){

    for (int atletaAtual = 0; atletaAtual < MAX_ATLETAS; atletaAtual++){

        for (int registoAtual = 0; registoAtual < MAX_REGISTOS_TEMPO; registoAtual++){

            printf("Insira o tempo %d do atleta %d:", registoAtual + 1, atletaAtual + 1);
            scanf("%f", &(tabelaTempos[atletaAtual])[registoAtual]);

        }

    }

}

float calcMedia(float tabelaTempos[][MAX_REGISTOS_TEMPO], float media[]){

    for (int atletaAtual = 0; atletaAtual < MAX_ATLETAS; atletaAtual++){

        for (int registoAtual = 0; registoAtual < MAX_REGISTOS_TEMPO; registoAtual++){
            media[atletaAtual] += tabelaTempos[atletaAtual][registoAtual];

        }
        media[atletaAtual] /= (float)MAX_REGISTOS_TEMPO;

    }

    return 0;
}

void printarMedia(float media[]){

    for (int mediaAtual = 0; mediaAtual < MAX_ATLETAS; mediaAtual++){
        printf("A média de tempo do atleta %d é:%.2f.\n", mediaAtual + 1, media[mediaAtual]);
    }

}


int main(){

    float tabelaTempos[MAX_ATLETAS][MAX_REGISTOS_TEMPO];
    float media[3];

    inserirTempos(tabelaTempos);
    calcMedia(tabelaTempos, media);
    printarMedia(media);

    return 0;
}
Link to comment
Share on other sites

On 12/16/2019 at 7:25 PM, João Antunes said:

Como posso tirar o valor mais alto de cada atleta? e trocar a media do atleta pela media dos tempos 1 dos tempos 2 . . . 

É percorrer os valores, verificar e guardar o valoe mais alto.

Trocar como assim?

O que está a acontecer? Isola o erro. diz o que acontece e o que devia acontecer. Usa printfs para ires vendo os valores das variáveis.

Kurt Cobain - Grunge misses you

Nissan GT-R - beast killer

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.