一.基本格式
1.固定格式
#include <iostream>
using namespace std ;
int main(){
}
请在
int main(){
程序哟
}写程序
2.运算符号
和python的不同:
1.除法的不同
默认是整除;加上‘.0'即可小数除法
3.输入与输出
#include <iostream>
using namespace std ;
int main(){
cout<<1145;
cout<<11+45<<endl;
cout<<5*2<<endl;
cout<<5/2<<endl;
cout<<5.0/2<<endl;
cout<<5%2<<endl;
1.输出
#include <iostream>
using namespace std ;
int main(){
cout<<1145;
}
cout就是输出;在1145后加上<<endl即可从不换行转为换行
例:
#include <iostream>
using namespace std ;
int main(){
cout<<1145;
cout<<1145<<endl;
}
2.输入
输入的是cin>>
注意这里用的是>>而不是<<
这取决于代码的流向
例子2:

#include <iostream>
using namespace std ;
int main(){
int q;
int w;
cin>>q>>w;
cout<<q/w<<" "<<q%w;
}
似乎比python简单
例题3
#include <iostream>
using namespace std ;
int main(){
int q;
int w;
cin>>q>>w;
cout<<(w-q)*30;
}
例题4
#include <iostream>
#include <iomanip>
using namespace std ;
int main(){
int q;
int w;
cin>>q;
w=q*9/5+32;
cout<<fixed<<setprecision(2)<<w<<endl;
}
4解析:
1.fixed<<setprecision(2)<<
将输出保留两位数
注意要配合
#include <iomanip>
例题5
#include <iostream>
#include <iomanip>
using namespace std ;
int main(){
float q;
float w;
cin>>q;
w=q/(2.0*3.14)*q/(2.0*3.14)*3.14;
cout<<fixed<<setprecision(2)<<w<<endl;
}

被折叠的 条评论
为什么被折叠?



