Hi Debojit Acharjee,
Normally this doesn't happen, please tell me what compiler you are using? What is an operating system? Here's what I get in VS2022:
Assigns the integer constant 1 to the long double variable a and prints it using the %Lf format string. According to the C language standard, the integer constant 1 is implicitly converted to type long double in this case. Regarding the issue with the output being -0.000000 , this may be due to the default printing precision for long double types.
You can specify a higher printing precision. I suggest you use %.0Lf to print an integer value and make sure no fractional part is displayed.
printf("%.0Lf", a);
If you want the decimal part to appear in the output, I suggest you use the %.6Lf format string, where .6 means set the printing precision to 6 decimal places.
You could also try printf("%Le", a);
to output it using scientific notation.
Best regards,
Elya Yao
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.