# Get Started With Coding – Tutorial For a Simple Addition Problem

New to the programming world, yet intrigued? Let’s get you started with the CodeChef journey with a very basic “Add Two Numbers” problem. So in this I shall explain both Python and C++ solutions.

The problem is to find the sum of 2 integers that we give as input. As mentioned in the problem, the user (or Shivam) inputs the number of test cases (T) in the first line. Then followed by T lines, each line contains two integers A and B. So the logic here is simple, right? First, you need to input the number of test cases, then input the numbers you want to add, and the sum of the numbers is displayed as the output. The input function lets us take a text input from the user and the output function gives the data processed by the program.

## Solution in Python

Let us first take a look at how the program can be executed using Python. Before we get into the solution, we will have a look at the ‘for’ loop. A ‘for’ loop is an entry check loop which executes only if the condition is satisfied at the beginning. You can specify the range for the ‘for’ loop to iterate over. So now we will get into the logic of the problem.

• Your first input variable must be ‘ test case’. You can name this variable, for instance, T.
• The next input, i.e., the numbers you want to sum, is inputted in a ‘for’ loop. The range for the ‘for’ loop is the integer stored in the test case variable.
• Next, the split function is used to split the given string by the specified separator.
• The next step would be to input the numbers you want to add, and these are stored in 2 variables, a and b.
• Using the print function the sum of the numbers is printed.

## Solution in C++

We shall now see how the same logic would be in C++. Instead of using the input() function, here it is ‘cin’.

• First, the test case integer is inputted and stored in a variable (refer it to as ‘a’).
• Then iterating over the ‘for’ loop from 0 to a+1, the numbers are entered by the user.
• Another variable, ‘C’ is created where the summation of the two numbers is stored.
• Later the output is printed using the ‘cout’ statement.

Well, that was easy, right? Now head over and solve more problems!

## A Starters Like Never Before | Action-Packed Ranklists &…

The first Starters of the month, which was rated for both Divisions, ended yesterday night, and it would be an understatement to say that... riddhi_225

## Can You Fly The Best Yet The Cheapest Route…

Hola! When was the last time you boarded a flight for a vacation? Every time we plan and book the flights a minimum of... ganga4518

## Rising Stars | October Long Challenge 2021

October Long Challenge 2021, the first-rated challenge of the month, was surreal! While we saw lots of top coders maintain their high ranks and... ganga4518

## 7 Replies to “Get Started With Coding – Tutorial For a Simple…”

1. khetesh_47 says:

#include

int main(void) {
int T,a,b,i;
scanf(“%d”,&T);
for(i=0;i<T;i++)
{
scanf("%d%d",&a,&b);
printf("%d\n",a+b);
}
return 0;
}

2. shraddha_2808 says:

#include
using namespace std;
int main()
{
int a, b;
int c=0;
cout<>a;
cout<>b;
c=a+b;
cout<<"a+b="<<c;

return 0;
}

3. it_3_12b4 says:

#include
using namespace std;
int main()
{
int a, b;
int c=0;
couta;
coutb;
c=a+b;
cout<<"a+b="<<c;

return 0;
}

4. blitz_flash says:

#include
using namespace std;
int main()
{
int a,b;
cout<<"Enter two numbers "<<a<<" '<<b<<endl;
cout<<"The sum is"<<a+b;
return 0;
}

5. utkarsh0427 says:

dont anyone know python here ..why everyone is writing in c c++ only

1. deepakguler123 says:

ahahhahahaha…..

6. prassu_12 says:

n=int(input())
a=1
b=2
c=100
d=200
e=10
f=40
Print(a+b,c+d,e+f)