구구단 (2739)
Created:
간단한 구구단
Bash
Bash 1
2
3
4
read n
for i in {1..9}; do
echo $n \* $i = $((n * i))
done
C
C 1
2
3
4
5
6
7
8
9
10
11
#include <stdio.h>
int main(void) {
int n;
scanf("%d", &n);
for (int i=1; i<=9; i++) {
printf("%d * %d = %d\n", n, i, n*i);
}
return 0;
}
Node.js
JavaScript 1
2
3
4
let n = Number(require("fs").readFileSync(0).toString().trim());
for (let i=1; i<=9; i++) {
console.log(`${n} * ${i} = ${n*i}`);
}
PHP
PHP 1
2
3
4
5
6
<?php
fscanf(STDIN, "%d", $n);
for ($i=1; $i<=9; $i++) {
echo "$n * $i = ".$n*$i."\n";
}
?>
Python3
Python 1
2
3
n = int(input())
for i in range(1, 10):
print("{} * {} = {}".format(n, i, n*i))
Ruby
Ruby 1
2
3
4
n = gets.chomp.to_i
for i in 1..9
puts "#{n} * #{i} = #{n*i}"
end