题目要求:编写一个代码,能够实现任意输入两个数字A和B,结果计算出A+B之和。
解答步骤解析:
#include<cstdio> //定义输入/输出函数,cstdio是将stdio.h的内容用C++头文件的形式表示出来
#include<queue> //STL 队列容器
#include<cstring> //字符串处理
#include <vector> //STL 动态数组容器
#include<algorithm> //STL 通用算法
#include <iostream> //基本输入流
#include <string> //字符串处理
#include<sstream> //基于字符串的流
using namespace std; //命名空间
int a, b; //定义两个整数
int main() //主函数
{
while(cin>>a>>b){ //输入两个数字
cout<<a+b<<endl; //输出两个数字之和
#include<queue> //STL 队列容器
#include<cstring> //字符串处理
#include <vector> //STL 动态数组容器
#include<algorithm> //STL 通用算法
#include <iostream> //基本输入流
#include <string> //字符串处理
#include<sstream> //基于字符串的流
using namespace std; //命名空间
int a, b; //定义两个整数
int main() //主函数
{
while(cin>>a>>b){ //输入两个数字
cout<<a+b<<endl; //输出两个数字之和
}
}
}
运行结果:每当输入任意两个数时,按“Enter”键,系统就会自动算出输入任意的两个数之和。
做题应该注意的问题:
1、首先要先看懂题目,弄清楚题目的要求;
2、其次,确定好编码所要使用的语言;
3、最后,根据题目要求,来一步步编写,每一步用到的代码都要弄清楚其的功能,才能够完整实现整个程序的功能;