Code3TP1.c 1.33 KB
#include <stdio.h>

float somme(float reel1, float reel2) {
    float sum2;
    sum2 = reel1 + reel2;
    return(sum2);
}

void MinMax(float a, float b, float c, float *min, float *max) {
    *min = a;
    *max = a;
    if(b>=a && b>=c){
        *max = b;}
    else{
    if(c>=a && c>=b){
        *max = c;}}
    if(b<=a && b<=c){
        *min = b;}
    else{
        if(c<=a && c<=b){
        *min = c;}}
}
    
void TraitementSuite(float *min, float *max, float *moy, int *existe){
    float r, sum;
    int i;
    sum =0;
    printf("Saisir une suite de réels se terminant par 0 :\n");
    scanf("%f",&r);
    i=0;
    if (r==0){
        printf("Votre suite ne contient aucun réels\n");
        *existe = 0;
    }
    else{
        *min = r;
        *max = r;
    
        while(r!=0){
            sum = somme(sum, r);
            MinMax(r, *min, *max, min, max);
            i=i+1;
            scanf("%f", &r);
        }
    *moy = sum/i;
    *existe = 1;
    }
}
    
int main(){
    float min, max, moy;
    int existe;
    TraitementSuite(&min, &max, &moy, &existe);
    if (existe == 1){
    printf("Le min de la suite est %f, son max est %f et sa moyenne est %f \n", min, max, moy);
    }
    else{
        printf("Impossible de déterminer la moyenne, le min et le max \n");}
    return(0);}