A+B is one of the most complex problems on this website due to its large variety of solutions.
C
1 #include<stdio.h>
2
3 int main(void) {
4 int a, b;
5 scanf("%d%d", &a, &b);
6 printf("%d", a + b);
7 return 0;
8 }
C++
1 #include<iostream>
2
3 int main(void){
4 int a, b;
5 std::cin >> a >> b;
6 std::cout << a + b;
7 return 0;
8 }
D
1 import std.stdio;
2
3 void main(){
4 long a, b;
5 readf("%d %d", &a, &b);
6 writeln(a+b);
7 }
Go
1 package main
2 import "fmt"
3
4 func main() {
5 var a, b int
6 fmt.Scanf("%d%d", &a, &b)
7 fmt.Print(a + b)
8 }
GolfScript 1 ~+
Haskell
1 import Control.Applicative
2
3 main :: IO ()
4 main = do
5 [ a, b ] <- map read . words <$> getLine
6 print (a + b :: Int)
Java
In Java, the class must be named
prog
.
1 public class prog {
2 public static void main(final String[] args) {
3 java.util.Scanner scan = new java.util.Scanner(System.in);
4 System.out.println(scan.nextInt() + scan.nextInt());
5 }
6 }
Oberon
1 MODULE prog;
2
3 IMPORT In, Out;
4
5 VAR a, b : INTEGER;
6
7 BEGIN
8 In.Int(a);
9 In.Int(b);
10 Out.Int(a + b, 0);
11 Out.Ln
12 END prog.
OCaml
1 let sum a b = a + b
2
3 let _=
4 Printf.printf "%i\n" ((Scanf.scanf "%i %i" sum))
Pascal
1 var a,b:integer;
2 begin
3 read(a,b);
4 write(a+b);
5 end.
Perl
1 #!/usr/bin/perl
2 use v5.14;
3 use warnings;
4
5 my ($x, $y) = split ' ', <>;
6 say $x + $y;
PHP
1 <?php
2 fscanf(STDIN, "%d %d\n", $a, $b);
3 echo $a+$b . "\n";
4 ?>
Python
1 #!/usr/bin/python
2 print sum(map(int, raw_input().split()))
Python3
1 #!/usr/bin/python3
2 print(sum(map(int, input().split())))
Ruby
1 p gets.split(' ').map(&:to_i).inject 0, :+
Rust
1 use std::io;
2
3 fn main() {
4 let mut input = String::new();
5
6 let _ = io::stdin().read_line(&mut input);
7
8 let mut sum: i64 = 0;
9 for x in input.trim().split(" ").collect::<Vec<&str>>() {
10 sum += match x.parse::<i64>() {
11 Ok(val) => val,
12 _ => 0,
13 };
14 }
15
16 println!("{}", sum);
17 }
SBCL
1 (format t "~d" (+ (read) (read)))