C Programming - Floating Point Issues - Discussion

Discussion :: Floating Point Issues - General Questions (Q.No.5)

5. 

Which statement will you add in the following program to work it correctly?

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

[A]. #include<conio.h>
[B]. #include<math.h>
[C]. #include<stdlib.h>
[D]. #include<dos.h>

Answer: Option B

Explanation:

math.h is a header file in the standard library of C programming language designed for basic mathematical operations.

Declaration syntax: double log(double);


Vinay Airan said: (Jul 20, 2010)  
#include<stdio.h>
#include<math.h>

int main()
{
printf("%f\n", log(36.0));
return 0;
}

While i compile this code there is an error like..

In function `main':
undefined reference to `log'

why??

Kumar said: (Jul 21, 2010)  
Since C is a compiler dependent language, it may give different outputs at different platforms. Here the Turbo-C Compiler (Windows) output has been given.

Please try the above programs in Windows (Turbo-C Compiler) and Linux (GCC Compiler), you will understand the difference better.

Well Wisher said: (Feb 10, 2011)  
Kumar is correct.

Varun said: (Apr 4, 2011)  
What should be added here (in this case) to make output correct.

Devendra said: (Aug 20, 2011)  
If we use stdio.h,ans. is -.000901 and using math.h ans is -.001263

Why is it different?

Hajmaldeen said: (Dec 20, 2011)  
How to run this program to unix?

Pratap Singh said: (Aug 16, 2012)  
unsigned int i=65535;
int j;
j=i;
printf("%d",j);
output

-1 //// Why the output of j=-1 ....Please explain this


int j=-2;
unsigned int i=1+j;
printf("%u",i);
output

65535 //// Wht the output of i=65535

Satti said: (Oct 12, 2012)  
Range of signed integer is -32768 to 32767
but in unsigned integer case range is 65535
ie) 32768=-32768
32769=-32767
32770=-32766
.
.
.
65535=-1
thats why processor prints -1.
in ur second quetn j=-2
but i=1+j so i=-1; so the output prints 65535

Deepa said: (Oct 7, 2014)  
What are the different b/w stdio, conio, stdlib? could any one?

Suyoj said: (Nov 5, 2014)  
What is the difference between getch and getche ?

Mallikarjun said: (Jan 30, 2015)  
float 3.12;
{
scanf("2.1%f",&a);
}

Output? And in this program what is 2.1%f?

Please explain who know about this?

Muhammed Shafeek Kp said: (Sep 26, 2016)  
#include<stdio.h>
int main()
{
printf("%f\n", log(36.0));
return 0;
}

What is the output of this program?

Can I run this program by using #include<conio.h>?

Rajat Bhise said: (Jan 27, 2019)  
@Satti.

#include<stdio.h>
main()
{
int a,b,c;
a=32767;
b=32768;
c=32769;
printf("a=%d,b=%d,c=%d",a,b,c);
}


Output is
a=32767
b=-32768
c=-32769 this type of output is in book
But;

My output is;
a=32767
b=32768
c=32769
The '-' minus sign is not find how? Please explain this.

Aadhiii said: (Sep 13, 2019)  
@Satti.

#include<stdio.h>
main()
{
int a,b,c;
a=32767;
b=32768;
c=32769;
printf("a=%d,b=%d,c=%d",a,b,c);
}


Output is
a=32767
b=-32768
c=-32769 this type of output is in book
But;

My output is;
a=32767
b=32768
c=32769

The '-' minus sign is not find how? Please explain this.

Post your comments here:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.