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ラーニングレベルアップ問題集の「掛け算」をやってみた。

Last updated at Posted at 2025-02-07

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


問題


以下のコードでは、受け取った入力値を直接オペランド(被演算子)として扱っています。速さを競う競技プログラミングや、短さを競うコードゴルフの時は構いませんが、通常は、入力値を一旦変数に格納する等、コーディング規約に従って頂ければと思います。


C
#include <stdio.h>

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

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

int main() {
	int a;
	cin >> a;
	int b;
	cin >> b;
	cout << a * b << endl;
	return 0;
}

C#
using System;

class Program
{
	public static void Main()
	{
		Console.WriteLine(int.Parse(Console.ReadLine()) * int.Parse(Console.ReadLine()));
	}
}

Go
package main
import "fmt"

func main() {
	var a int
	fmt.Scan(&a)
	var b int
	fmt.Scan(&b)
	fmt.Println(a * b)
}

Java
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		System.out.println(sc.nextInt() * sc.nextInt());
		sc.close();
	}
}

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

Kotlin
fun main() {
	println(readLine()!!.toInt() * readLine()!!.toInt())
}

PHP
<?php
	echo fgets(STDIN) * fgets(STDIN), PHP_EOL;
?>

Perl
print <STDIN> * <STDIN>, $/;

Python3
print(int(input()) * int(input()))

Ruby
p gets.to_i * gets.to_i

Scala
import scala.io.StdIn._

object Main extends App{
	println(readInt() * readInt())
}

Swift
print(Int(readLine()!)! * Int(readLine()!)!)

その他のDランク見本・過去問題

2024年7月19日~8月29日に行われたpaiza×Qiitaコラボキャンペーンで投稿した記事です。

足し算
一番小さい値
文字の一致
Eメールアドレス
N倍の文字列
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?