problem with printf function?

前端 未结 5 1871
Happy的楠姐
Happy的楠姐 2020-12-20 03:28

i wrote the following program

 #include 

 main()
 {
 int i = 2;
 float c = 4.5;
 printf(\"%d\\n\",c);
 printf(\"%f\\n\",i);
 return 0;
 }
         


        
5条回答
  •  南笙
    南笙 (楼主)
    2020-12-20 04:15

    Basically, format controls replace the placeholder according to specified data type.

    • %d expects argument of type int
    • %f expects argument of type double

    So Good way of doing this is

    #include 
    
    int main(){
       int i = 2;
       float c = 4.5;
       printf("%d\n",i);
       printf("%f\n",c);
       return 0;
    }
    

提交回复
热议问题