在编程中,++运算符是使操作数的值增加1的增量运算符。我们可以通过将数字a,b的次数加1来使用此运算符将两个数字相加。
例,
Input: a = 31 , b = 4 Output: 35
解释-将1乘以31至四次,总和为31 + 1 + 1 + 1 + 1 = 35。
Input: two integers a and b. Step 1: loop from 0 to b and follow step 2. Step 2: add 1 to b. Step 3: print the value of a.
#include <iostream>
using namespace std;
int main(){
int x = 324 , y= 76;
cout<<"The sum of "<<x<<" & "<<y;
if(y>0){
for(int i= 0; i<y;i++){
x++;
}
} else {
for(int i= y; i<0;i++){
x--;
}
}
cout<<" is "<<x;
return 0;
}输出结果
The sum of 324 & 76 is 400