In the code below, printf prints -0.00000. What is the problem? If it is double instead of long double, then it works fine.
#include<stdio.h>
long double abs1(long double x) {
if (x<0.0)
return -1.0*x;
else
return x;
}
main() {
long double z=abs1(4.1);
printf("%llf\n",z);
}
The correct print format for a long double is %Lf. Turning on your compiler's warnings would have pointed out the mistake immediately:
$ gcc -Wall b.c -o b b.c:9: warning: return type defaults to `int' b.c: In function `main': b.c:11: warning: use of `ll' length modifier with `f' type character b.c:11: warning: use of `ll' length modifier with `f' type character b.c:12: warning: control reaches end of non-void function
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With