An integer n is given. For i from 1 to 9, print 9 lines of the form "n x i = r", where r is n × i. The multiplication sign is a lowercase letter x, and there is exactly one space on each side of x and of =. Use the same form when n is 0 or negative (e.g. -2 x 3 = -6).
Input
one integer n (-1000 ≤ n ≤ 1000)
Output
9 lines
Example 1 · stdin
3
stdout
3 x 1 = 3
3 x 2 = 6
3 x 3 = 9
3 x 4 = 12
3 x 5 = 15
3 x 6 = 18
3 x 7 = 21
3 x 8 = 24
3 x 9 = 27
main.py
Error List00F8 ↓ · ⇧F8 ↑
Input (stdin)
When you run, these lines are fed to input()/stdin in order (the program doesn't stop to ask).
$ Ready
Open this on a computer to write and run code. On mobile you can read the problem and the solutions.
In other languagesShow solutions by language · 8 languages
Whether the last number is included is the first trap. Python range(1, 10) stops before 10, giving 1–9; writing range(1, 9) drops the ×9 line. C-style for (i = 1; i <= 9; i++) uses <=, so 9 is included. The second trap is spaces: when gluing pieces together it is easy to produce "3x1=3". Formatting differs by language: Python f"{n} x {i} = {n * i}", JS/TS template literals `${n} x ${i} = ${n * i}, C# $"{n} x {i} = {n * i}", C and Java printf("%d x %d = %d\n", …) (Java uses %n for the newline), C++ chains <<`. Craykon has no string interpolation yet, so join with +: n + " x " + i + " = " + n * i (* binds before +, so the product is computed first without parentheses).
Pythonmain.py · 3 lines
n = int(input())for i in range(1, 10): print(f"{n} x {i} = {n * i}")
JavaScriptmain.js · 4 lines
const n = Number(require("fs").readFileSync(0, "utf8").trim());for (let i = 1; i <= 9; i++) { console.log(`${n} x ${i} = ${n * i}`);}
TypeScriptmain.ts · 5 lines
import { readFileSync } from "node:fs";const n: number = Number(readFileSync(0, "utf8").trim());for (let i = 1; i <= 9; i++) { console.log(`${n} x ${i} = ${n * i}`);}
JavaMain.java · 10 lines
import java.util.Scanner;public class Main { public static void main(String[] args) { int n = new Scanner(System.in).nextInt(); for (int i = 1; i <= 9; i++) { System.out.printf("%d x %d = %d%n", n, i, n * i); } }}
C#Main.cs · 13 lines
using System;class Program{ static void Main() { int n = int.Parse(Console.ReadLine()); for (int i = 1; i <= 9; i++) { Console.WriteLine($"{n} x {i} = {n * i}"); } }}
C++main.cpp · 9 lines
#include <iostream>int main() { int n; std::cin >> n; for (int i = 1; i <= 9; i++) { std::cout << n << " x " << i << " = " << n * i << "\n"; }}
Cmain.c · 10 lines
#include <stdio.h>int main(void) { int n; scanf("%d", &n); for (int i = 1; i <= 9; i++) { printf("%d x %d = %d\n", n, i, n * i); } return 0;}
Craykonmain.cray · 5 lines
n = Console.ReadLine().ToNumber();for (i = 1; i <= 9; i++){ Console.WriteLine(n + " x " + i + " = " + n * i);}