在生活中,以及c++的基础,都需要用到加法,数学中更是如此,以下是c++实现a+b的方法
1.变量实现
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a,b;
int sum=0; //需要提前赋初值,否则sum的值是随机的
cin>>a>>b;
sum=a+b;
cout<<sum<<endl;
return 0;
}
2.直接输出
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a,b;
cin>>a>>b;
cout<<a+b<<endl;
return 0;
}
1374


&spm=1001.2101.3001.11974&articleId=135248898&d=1&t=3&u=f980071fb79a4c4d93e72b3f68bc91d9)

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



