C Programming - Floating Point Issues - Discussion

Discussion Forum : Floating Point Issues - Yes / No Questions (Q.No. 1)
1.
Will the printf() statement print the same values for any values of a?
#include<stdio.h>
int main()
{
    float a;
    scanf("%f", &a);
    printf("%f\n", a+a+a);
    printf("%f\n", 3*a);
    return 0;
}
Yes
No
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
13 comments Page 2 of 2.

Ganesh Raj said:   9 years ago
It is not a^3 here. It's just 3*a. Then, how comes 387.064?

Kelvin desai said:   9 years ago
@Tamilmaran, it is showing correct only, check in terminal.

float f = 25.4;
printf("%f %f\n",f+f+f,f*3);

Output: 76.199999 76.199999

Kelvin desai said:   9 years ago
@Rupesh Sahu.

It is 25.4 * 3 not 25.4 * 25.4 * 25.4.


Post your comments here:

Your comments will be displayed after verification.