C Programming - Floating Point Issues - Discussion

Discussion Forum : 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;
}
#include<conio.h>
#include<math.h>
#include<stdlib.h>
#include<dos.h>
Answer: Option
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);

Discussion:
14 comments Page 1 of 2.

Rajat Bhise said:   7 years ago
@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:   6 years ago
@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.

Kumar said:   2 decades ago
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.

Satti said:   1 decade ago
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

Pratap Singh said:   1 decade ago
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

Vinay Airan said:   2 decades ago
#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??

Muhammed shafeek kp said:   9 years ago
#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>?

Mallikarjun said:   1 decade ago
float 3.12;
{
scanf("2.1%f",&a);
}

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

Please explain who know about this?

Devendra said:   1 decade ago
If we use stdio.h,ans. is -.000901 and using math.h ans is -.001263

Why is it different?

Varun said:   1 decade ago
What should be added here (in this case) to make output correct.


Post your comments here:

Your comments will be displayed after verification.