C Programming - Floating Point Issues - Discussion

Discussion :: Floating Point Issues - Find Output of Program (Q.No.4)

4. 

What will be the output of the program?

#include<stdio.h>
#include<math.h>
int main()
{
    printf("%f\n", sqrt(36.0));
    return 0;
}

[A]. 6.0
[B]. 6
[C]. 6.000000
[D]. Error: Prototype sqrt() not found.

Answer: Option C

Explanation:

printf("%f\n", sqrt(36.0)); It prints the square root of 36 in the float format(i.e 6.000000).

Declaration Syntax: double sqrt(double x) calculates and return the positive square root of the given number.


Gaurav said: (Apr 10, 2011)  
But sir, float has only 4 terms after decimal place and there is 6 six terms after decimal?

Ramkrishna said: (Apr 21, 2011)  
6.0 is allso float right? Why can't I become a answer please explain?

Rajaasekaran said: (Jul 22, 2011)  
Can you give me example program for square root of double ?

Surbhi said: (Aug 26, 2012)  
Why not 6.0?

Shailesh said: (Mar 1, 2013)  
Because.

36.0 is double.

6.0 is float.

So the answer 6.0 is not possible.

D Suresh said: (Apr 26, 2013)  
Generally float value will display like six digits after the decimal point so, output of the above program will be 6.000000 because sqrt (36.0) =6.000000.

Sankari said: (Aug 5, 2013)  
36.0 is double, how it is double can anyone explain me please?

What is double and float?

Nishant said: (Aug 9, 2013)  
But when I tried in turbo C it return 0. Why?

Yogesh Tiwari said: (Jan 16, 2014)  
Sir I am not satisfied with your answer, it turbo c it create error please explain.

Meghana said: (Oct 22, 2014)  
Can anyone explain me how 36.0 is double?

Ishi said: (Dec 10, 2014)  
@D Suresh.

As you said float value display six value after decimal than, what about double and long double?

Raj said: (Mar 28, 2015)  
How 36 is double, please explain?

Deepak said: (Jun 21, 2016)  
If 36.0 is double then it should give 14 digits of precision then answer would be 6.00000000000000.

Janavi said: (Aug 27, 2019)  
Generally, the float value will display like six digits after the decimal point so, the output of the above program will be 6.000000 because of √(36.0) =6.000000.

So whenever we have to calculate the sq.root of decimal digits there are always ans is value .000000.

Surbhi Rajput said: (Nov 1, 2019)  
How it can be double?

Post your comments here:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.