#include <stdio.h>
int main (){
float M=2E30, G=6.67E-11, m=6E24, r=1.5E11;
float F= (G*M*m)/(r*r);
printf("F is %f",F);
return 0;
}
I am trying to print the value of F
with two decimal precision. Could anyone help me please?
#include <stdio.h>
int main (){
float M=2E30, G=6.67E-11, m=6E24, r=1.5E11;
float F= (G*M*m)/(r*r);
printf("F is %f",F);
return 0;
}
I am trying to print the value of F
with two decimal precision. Could anyone help me please?
For two decimal precision, change your printf statement as below
printf("F is %.2f", F);
read this for more information.
You should try this:
printf("F is %0.2f",F);
The 0
in %0.2f
tells that the output need not to be right justified and the 2
after the decimal tells that there should be only 2 digits after the decimal in the output. Basically %0.nf
allows us to set a precision of n digits after the decimal in the output.
Hope this helps.