
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Add Two Numbers Using ++ Operator in C++
In programming, the ++ operator is the increment operator that increases the value of the operand by 1. We can add two numbers using this operator by adding 1 to the number a, b number of times.
Example,
Input: a = 31 , b = 4 Output: 35
Explanation − adding 1 to 31 four times, sums up to 31 +1+1+1+1 = 35.
Algorithm
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.
Example
#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; }
Output
The sum of 324 & 76 is 400
Advertisements