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

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -