I have a program in which if I use floats it outputs 29.325001
, but if I use double it's 29.325000
(that's the right result).
I thought that float rounds up to 14 decimal places, but it's producing a different result than expected?
Code below:
int elements, i;
scanf("%d", &elements);
if (elements > 10){
return 0;
}
float ppp[10], takeHowMuch[10], total;
for (i = 0; i < elements; i++){
scanf("%f", &ppp[i]);
}
for (i = 0; i < elements; i++){
scanf("%f", &takeHowMuch[i]);
}
total = (takeHowMuch[0] * ppp[0]) + (takeHowMuch[1] * ppp[1]) + (takeHowMuch[2] * ppp[2]) + (takeHowMuch[3] * ppp[3]);
printf("%.6f", total);
return 0;