给出两个不大于100的正整数a和b,要你输出a+b的值。
给出两个不大于100的正整数a和b,要你输出a+b的值。
第一行有个T,表示有T组测试数据。接下来跟着T行,每行有2个整数表示每组测试数据的两个数a和b(1<=a,b<=100)
对于每组测试数据输出一个数字表示a+b的值,并且每组输出占一行。
下面将展示出几种不同编程语言下本题的实现代码:
#include <stdio.h> #include <stdlib.h> int main () { int a, b, t, sum; scanf ("%d", &t); while (t--) { scanf ("%d %d", &a, &b); sum = a + b; printf ("%d\n", sum); } return 0; }
#include <iostream> using namespace std; int main () { int a, b; int t; cin >> t; while (t--) { cin >> a >> b; int sum = a + b; cout << sum << endl; } return 0; }
import java.util.*; public class Main { public static void main (String[] args) { Scanner scanner = new Scanner(System.in); int a, b,t; t = scanner.nextInt(); while (t > 0) { t--; a = scanner.nextInt(); b = scanner.nextInt(); int sum; sum = a + b; System.out.println (sum); } } }
2
1 1
2 2
2
4