BOJ 10869 사칙연산

1 개요[ | ]

BOJ 10869 사칙연산

[[분류:BOJ {{{단계}}}단계]]

  • 1단계
  • 모든 사칙연산 해보기
  • 알고리즘 분류: 사칙연산

2 C[ | ]

#include <stdio.h>
int main() {
	int a, b;
	scanf("%d %d",&a,&b);
	printf("%d\n",a+b);
	printf("%d\n",a-b);
	printf("%d\n",a*b);
	printf("%d\n",a/b);
	printf("%d\n",a%b);
	return 0;
}

3 C++[ | ]

#include <iostream>
using namespace std;
int main() {
    auto a=0, b=0;
    cin >> a >> b;
    cout << a+b << endl;
    cout << a-b << endl;
    cout << a*b << endl;
    cout << a/b << endl;
    cout << a%b << endl;
    return 0;
}

4 C#[ | ]

using System;
public class Program {
    public static void Main() {
        string s = Console.ReadLine();
        string[] ss = s.Split();
        int a = int.Parse(ss[0]);
        int b = int.Parse(ss[1]);
        Console.WriteLine(a+b);
        Console.WriteLine(a-b);
        Console.WriteLine(a*b);
        Console.WriteLine(a/b);
        Console.WriteLine(a%b);
    }
}

5 Go[ | ]

package main
import "fmt"
func main() {
    var a, b int
    fmt.Scanf("%d %d", &a, &b)
    fmt.Printf("%d\n", a+b)
    fmt.Printf("%d\n", a-b)
    fmt.Printf("%d\n", a*b)
    fmt.Printf("%d\n", a/b)
    fmt.Printf("%d\n", a%b)
}

6 Java[ | ]

import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        System.out.println( a + b );
        System.out.println( a - b );
        System.out.println( a * b );
        System.out.println( a / b );
        System.out.println( a % b );
    }
}

7 node.js[ | ]

var fs = require('fs');
var input = fs.readFileSync('/dev/stdin').toString().split(' ');
var a = parseInt(input[0]);
var b = parseInt(input[1]);
console.log(a+b);
console.log(a-b);
console.log(a*b);
console.log(Math.floor(a/b));
console.log(a%b);

8 Perl[ | ]

use 5.010;
($a, $b) = split(/ /, <>);
say($a + $b);
say($a - $b);
say($a * $b);
say(int($a / $b));
say($a % $b);

9 PHP[ | ]

<?php
fscanf(STDIN,"%d %d",$a,$b);
fprintf(STDOUT,"%d\n",$a+$b);
fprintf(STDOUT,"%d\n",$a-$b);
fprintf(STDOUT,"%d\n",$a*$b);
fprintf(STDOUT,"%d\n",$a/$b);
fprintf(STDOUT,"%d\n",$a%$b);

10 Python[ | ]

a, b = map(int, input().split())
print(a+b)
print(a-b)
print(a*b)
print(a//b)
print(a%b)
a, b = map(int, input().split())
print(a+b)
print(a-b)
print(a*b)
print(int(a/b))
print(a%b)

11 R[ | ]

fp=file("stdin", "r")
a=scan(file=fp, what=integer(0), n=1)
b=scan(file=fp, what=integer(0), n=1)
cat(a+b, "\n")
cat(a-b, "\n")
cat(a*b, "\n")
cat(a%/%b, "\n")
cat(a%%b, "\n")

12 Ruby[ | ]

a, b = gets.split.map(&:to_i)
puts a + b
puts a - b
puts a * b
puts a / b
puts a % b
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}