I was doing a program which will simply calculate the aggregate and percentage marks of 5 subjects for a student. The full marks for each subject is 100 and the marks are input through the keyboard. I know that this program can be written in a 1000 ways. But I write in the following way and I got a mysterious output: The last digit of the 'percentage' output is erroneous. Why is this happening ? - Please point out the error.
Program:
#include<stdio.h>
main()
{
float m1,m2,m3,m4,m5;
printf(" enter the marks");
scanf("%f%f%f%f%f",&m1,&m2,&m3,&m4,&m5);
printf(" Aggregate marks = %f \n Percentage marks = %f \n ", m1+m2+m3+m4+m5,(m1+m2+m3+m4+m5)/5);
}
Input: 53 25 26 98 49
Output:
Aggregate marks = 251.000000
Percentage marks = 50.200001
See the last digit of percentage marks. It is erroneous.
Note: I am using Pelles C , Version = 7.00.355