Go語言程式列印指定數字的乘法表
步驟
- 讀取一個數字並將其儲存在一個變數中。
- 列印給定數字的乘法表。
| 輸入要列印乘法表的數字:7 7 x 1 = 7 7 x 2 = 14 7 x 3 = 21 7 x 4 = 28 7 x 5 = 35 7 x 6 = 42 7 x 7 = 49 7 x 8 = 56 7 x 9 = 63 7 x 10 = 70 | 輸入要列印乘法表的數字:17 17 x 1 = 7 17 x 2 = 34 17 x 3 = 51 17 x 4 = 68 17 x 5 = 85 17 x 6 = 102 17 x 7 = 119 17 x 8 = 136 17 x 9 = 153 17 x 10 = 170 |
解釋
- 使用者必須輸入一個數字。
- 使用 print 語句列印給定數字的乘法表。
示例
package main
import "fmt"
func main(){
var n int
fmt.Print("Enter the number to print the multiplication table:")
fmt.Scanf("%d", &n)
for i:=1; i<11; i++ {
fmt.Println(n, "x", i, "=", n*i)
}
}輸出
Enter the number to print the multiplication table: 7 7 x 1 = 7 7 x 2 = 14 7 x 3 = 21 7 x 4 = 28 7 x 5 = 35 7 x 6 = 42 7 x 7 = 49 7 x 8 = 56 7 x 9 = 63 7 x 10 = 70
廣告
資料結構
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C語言程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP