DEV_BUT1/DEV1.1/CM1/calculs.c

27 lines
569 B
C
Raw Normal View History

2023-02-08 11:18:16 +01:00
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main(void){
int NOMBRE = 5;
double CIBLE = 51.7;
double tab[NOMBRE];
int i;
double res = 100000;
int proche = 0;
for(i = 0; i< NOMBRE; i++){
printf("Entrez une valeur : ");
scanf("%lf", &tab[i]);
printf("case n° %d : ", i);
printf("%.2lf\n", tab[i]);
}
res = fabs(tab[0] - CIBLE);
for(i = 1; i < NOMBRE; i++){
if (fabs(tab[i] - CIBLE) <= res){
res = fabs(tab[i] - CIBLE);
proche = i;
}
}
printf("La valeur la plus proche est dans la case n° %d\n", proche);
return 0;
}