c - basic, about specifier -


#include<stdio.h>  int main(){   double n1,n2;   float n3;   printf("input 2 flt:");   scanf("%lf %lf",&n1,&n2);   n3 = n1 * n2;   printf("n1 * n2 = %.2lf",n3); } 

when set n1,n2 float, n3 cannot correctly calculated ,why?

code a online tutorial, modified test function of %lf.

you must use %f.

#include  <stdio.h> int main(){ float n1,n2; float n3; printf("input 2 flt:"); scanf("%f %f",&n1,&n2); n3 = n1 * n2; printf("n1 * n2 = %.2f",n3); } 

Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -