Add two numbers(why is it showing wrong answer?)

we have to add two numbers such that
input:
2
5 6
7 8
output:
2
11
15
in this case,2 is number of cases and we have to add 5 and 6,7 and 8.
my code is like:
#include<stdio.h>

int main() { int T,A,B,i;
scanf("%d",&T);
for (i=1;i<=T;i++)
{
scanf("%d",&A);
scanf("%d",&B);
printf("%d",A+B);
}
return 0;

}
what is wrong in my code?

Print output of each testcase on new line.
You need to change the printf to printf("%d\n",A+B).

Me to Have The Same Issue.!

My Code :

#include
int main()
{
int T;
std::cin>>T;
int A,B;
for(int i =1;i<=T;i++)
{
std::cin>>A>>B;
std::cout<<A+B;
}
}

If You See The Condition To Produce The Ouput.

Firstly We have to get n inputs from the user and then print the n outputs(in this case …sum of (n) two numbers).

But In Both of our codes.
we printed the output ,next to each iteration(which is not the given condition).

output in newline by giving << endl after cout<< A+B

1 Like

Always ensure that your solution gives the correct output for the provided Example Input before you try to submit :slight_smile:

#include

using namespace std;

int main()
{
int t;
cin>>t;
int a,b;
for(int i=0;i<t;i++){
cin>>a>>b;
a=a+b;
cout<<a<<"\n";
}
}

Input::
2
5 6
7 8

OUTPUT:::
11
15