Add two numbers solution in C language.- Codechef
ADD TWO NUMBERS
Problem Code: FLOW001
Shivam is the youngest programmer in the world, he is just 12 years old. Shivam is learning programming and today he is writing his first program.
Program is very simple, Given two integers A and B, write a program to add these two numbers.
Input
The first line contains an integer T, the total number of test cases. Then follow T lines, each line contains two Integers A and B.
Output
For each test case, add A and B and display it in a new line.
Constraints
- 1 ≤ T ≤ 1000
- 0 ≤ A,B ≤ 10000
Example
Input 3 1 2 100 200 10 40 Output 3 300 50
. . .
Solution in C.
#include <stdio.h>
int main() {
int T;
scanf("%d", &T);
while (T--) {
int a, b;
scanf("%d %d", &a, &b);
int ans = a + b;
printf("%d\n", ans);
}
return 0;
}
Explanation:-
- First take the input T (total number of test cases).
- Use while loop (until T>0).
- Take two variables a and b as input from user.
- Do addition of a and b using arithmetic operator '+'.
- Display the ans obtained by adding a and b printf().
Try above code on C-Playground :- https://bit.ly/3gtHZIW
Comments
Post a Comment