大家注意,当除数定义为int 时,即使C定义为float型,输出结果仍然默认为取整数,故要将除数定位为float型,这样就能得到你想要的结果。
#include<iostream>
int main(int argc,char **argv)
{ float a=3;
int b=8;
float c=b / a;
std::cout<<"c:\n"<<c;
return 0;
}
#include<iostream>
int main(int argc,char **argv)
{ float a=3;
int b=8;
float c=b / a;
std::cout<<"c:\n"<<c;
return 0;
}
#include <stdio.h>
int main()
{
float a,b,c;
a=1;
b=2;
c = a /b;
printf("c: %f\n", c);
return 0;
}
int main()
{
float a,b,c;
a=1;
b=2;
c = a /b;
printf("c: %f\n", c);
return 0;
}
#include <stdio.h>
int main()
{
printf("Hello World! This is C Style\n");
printf("Hello World! This is C++ Style\n");
return 0;
}
int main()
{
printf("Hello World! This is C Style\n");
printf("Hello World! This is C++ Style\n");
return 0;
}
记住C++是用iostream
int main(int argc,char** argv){
std::cout<<"输入语句"<<std::endl;
return 0;
}
int main(int argc,char** argv){
std::cout<<"输入语句"<<std::endl;
return 0;
}