0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

paizaラーニングレベルアップ問題集の「引き算・掛け算」をやってみた。

Posted at

paizaラーニングレベルアップ問題集の引き算・掛け算をやってみました。


問題


C
#include <stdio.h>

int main() {
	int a, b;
	scanf("%d %d", &a, &b);
	int d = a - b;
	int p = a * b;
	printf("%d %d\n", d, p);
	return 0;
}

C++
#include <iostream>
using namespace std;

int main() {
	int a, b;
	cin >> a >> b;
	int d = a - b;
	int p = a * b;
	cout << d << ' ' << p << endl;
	return 0;
}

C#
using System;

class Program
{
	public static void Main()
	{
		int[] ab = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
		int d = ab[0] - ab[1];
		int p = ab[0] * ab[1];
		Console.WriteLine(d + " " + p);
	}
}

Go
package main
import "fmt"

func main() {
	var a, b int
	fmt.Scanf("%d %d", &a, &b)
	d := a - b
	p := a * b
	fmt.Printf("%d %d\n", d, p)
}

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();
		int d = a - b;
		int p = a * b;
		System.out.println(d + " " + p);
		sc.close();
	}
}

JavaScript
const [a, b] = require("fs").readFileSync("/dev/stdin", "utf8").trim().split(' ').map(Number);
const [d, p] = [a - b, a * b];
console.log(d, p);

Kotlin
import java.util.*

fun main() {
	val sc = Scanner(System.`in`)
	val a = sc.nextInt()
	val b = sc.nextInt()
	val d = a - b
	val p = a * b
	println("" + d + " " + p)
	sc.close()
}

PHP
<?php
	[$a, $b] = array_map("intval", explode(" ", trim(fgets(STDIN))));
	[$d, $p] = [$a - $b, $a * $b];
	echo "$d $p", PHP_EOL;
?>

Perl
my ($a, $b) = map { int($_) } split(' ', <STDIN>);
my ($d, $p) = ($a - $b, $a * $b);
print "$d $p$/";

Python3
a, b = map(int, input().split())
d, p = a - b, a * b
print(d, p)

Ruby
a, b = gets.split.map(&:to_i)
d, p = a - b, a * b
print d, ' ', p, "\n"

Scala
import scala.io.StdIn._

object Main extends App{
	val Array(a, b) = readLine().split(' ').map(_.toInt)
	val Array(d, p) = Array(a - b, a * b)
	println("" + d + " " + p)
}

Swift
let ab = readLine()!.split(separator: " ").map { Int($0)! }
let d = ab[0] - ab[1]
let p = ab[0] * ab[1]
print(d, p)
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?