Tính tổng 2 số nguyên
Xem dạng PDF
Gửi bài giải
Điểm:
100,00 (OI)
Giới hạn thời gian:
1.0s
Giới hạn bộ nhớ:
256M
Input:
stdin
Output:
stdout
Tác giả:
Dạng bài
Ngôn ngữ cho phép
C++, Python
Tính tổng 2 số nguyên
Mô tả và yêu cầu
CB02 - Tính tổng 2 số nguyên
Đề bài
Viết chương trình cho phép nhập số nguyên a và b từ bàn phím. Tính và in kết quả a + b
Dữ liệu vào
2 số nguyên a và b cách nhau 1 dấu cách
Dữ liệu ra
Tổng của a và b
Giới hạn và chấm điểm
∣a∣,∣b∣≤100
Ví dụ
Input #1
1 2
Output #1
3
Gợi ý
Đây là bài tập mẫu giúp các bạn làm quen hệ thống, do đó mình sẽ cung cấp lời giải mẫu để
các bạn tham khảo.
Lời giải C
#include <stdio.h>
int main(){
int a, b;
scanf("%d%d", &a, &b);
printf("%d\n", a+b);
return 0;
}
Lời giải Java
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner in=new Scanner(System.in);
int a=in.nextInt();
int b=in.nextInt();
System.out.println(a+b);
}
}
Lời giải C#
using System;
public class Program
{
static void Main(string[] args)
{
var numbers = Console.ReadLine();
var numberList = numbers.Split(' ');
var number1 = Convert.ToInt32(numberList[0]);
var number2 = Convert.ToInt32(numberList[1]);
Console.WriteLine(number1 + number2);
}
}
Lời giải Javascript 1
// Start of template
process.stdin.resume();
process.stdin.setEncoding('ascii');
// declare global variables
var input_stdin = "";
var input_stdin_array = "";
var input_currentline = 0;
// standard input is stored into input_stdin
process.stdin.on('data', function (data) {
input_stdin += data;
});
// standard input is done and stored into an array
// then main is called so that you can start processing your data
process.stdin.on('end', function () {
input_stdin_array = input_stdin.split("\n");
main();
});
// reads a line from the standard input array
function readLine() {
return input_stdin_array[input_currentline++];
}
// End of template
// Code here
function main() {
let a = readLine().split(' ');
console.log(parseInt(a[0]) + parseInt(a[1]));
}
Lời giải Javascript 2
const readline = require('readline');
const rl = readline.createInterface({ input: process.stdin });
rl.on('line', (input) => {
const [a, b] = input.split(' ').map(Number)
console.log(a + b);
});
Lời giải Python3
a, b = [int(x) for x in input().split()]
print(a+b)
Bình luận