Code3TP1.c
1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#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);}