Xiang
01-22-2003, 03:07 PM
Dear sir,
I want to find the average of the four values as below. Why my average was displayed in 15.676126 instead of the correct average is 15.676125.
#include <stdio.h>
#include <conio.h>
void main()
{
int v1 = 4;
int v2 = 42;
float v3 = 16.7;
float v4 = 0.0045;
float average;
clrscr();
printf("The four number are:\n");
printf("%i %i %g %g\n\n", v1, v2, v3, v4);
printf("The average is:\n");
average = (v1 + v2 + v3 + v4)/4;
printf("%f", average);
getch();
}
Thanks,
Xiang
I want to find the average of the four values as below. Why my average was displayed in 15.676126 instead of the correct average is 15.676125.
#include <stdio.h>
#include <conio.h>
void main()
{
int v1 = 4;
int v2 = 42;
float v3 = 16.7;
float v4 = 0.0045;
float average;
clrscr();
printf("The four number are:\n");
printf("%i %i %g %g\n\n", v1, v2, v3, v4);
printf("The average is:\n");
average = (v1 + v2 + v3 + v4)/4;
printf("%f", average);
getch();
}
Thanks,
Xiang