当前位置:网站首页>Example 008: 99 multiplication table
Example 008: 99 multiplication table
2022-07-05 08:22:00 【Lazy smile】
example 008: multiplication table
subject : Output 9*9 Multiplication table .
Program analysis : Branch and column considerations , common 9 That's ok 9 Column ,i The control line ,j Control the column .
# The first i Yes i Column ,range It is a semi closed and semi open interval, so range Need to go to i+1 # For better output , Set the result of multiplication to %-2d That accounts for 2 position ,- Indicates left alignment , No addition - Is the default right alignment end='' That is, no line break after output
The code is as follows :
for i in range(1, 10):
for j in range(1, i + 1): # The first i Yes i Column ,range It is a semi closed and semi open interval, so range Need to go to i+1
print('%d*%d=%-2d ' % (i, j, i * j), end='') # For better output , Set the result of multiplication to %-2d That accounts for 2 position ,- Indicates left alignment , No addition - Is the default right alignment end='' That is, no line break after output
print() # Line break
The output is as follows :
1*1=1
2*1=2 2*2=4
3*1=3 3*2=6 3*3=9
4*1=4 4*2=8 4*3=12 4*4=16
5*1=5 5*2=10 5*3=15 5*4=20 5*5=25
6*1=6 6*2=12 6*3=18 6*4=24 6*5=30 6*6=36
7*1=7 7*2=14 7*3=21 7*4=28 7*5=35 7*6=42 7*7=49
8*1=8 8*2=16 8*3=24 8*4=32 8*5=40 8*6=48 8*7=56 8*8=64
9*1=9 9*2=18 9*3=27 9*4=36 9*5=45 9*6=54 9*7=63 9*8=72 9*9=81
边栏推荐
- 【三层架构】
- Charge pump boost principle - this article will give you a simple understanding
- What are the test items of power battery ul2580
- Measurement fitting based on Halcon learning [II] meaure_ pin. Hdev routine
- OC and OD gate circuit
- PMSM dead time compensation
- Explain task scheduling based on Cortex-M3 in detail (Part 1)
- Basic information commands and functions of kernel development
- WiFi wpa_ Detailed description of supplicant hostpad interface
- General makefile (I) single C language compilation template
猜你喜欢
The firmware of the connected j-link does not support the following memory access
DCDC circuit - function of bootstrap capacitor
Solutions to compilation warnings in Quartus II
实例009:暂停一秒输出
Classic application of MOS transistor circuit design (1) -iic bidirectional level shift
Sword finger offer 09 Implementing queues with two stacks
Count the number of inputs (C language)
[trio basic from introduction to mastery tutorial XIV] trio realizes unit axis multi-color code capture
Installation and use of libjpeg and ligpng
STM32 summary (HAL Library) - DHT11 temperature sensor (intelligent safety assisted driving system)
随机推荐
[nas1] (2021cvpr) attentivenas: improving neural architecture search via attentive sampling (unfinished)
More than 90% of hardware engineers will encounter problems when MOS tubes are burned out!
Semiconductor devices (III) FET
实例008:九九乘法表
C WinForm [display real-time time in the status bar] - practical exercise 1
Circleq of linked list
2020-05-21
Volatile of C language
99 multiplication table (C language)
实例005:三数排序 输入三个整数x,y,z,请把这三个数由小到大输出。
My-basic application 2: my-basic installation and operation
实例007:copy 将一个列表的数据复制到另一个列表中。
Working principle and type selection of common mode inductor
STM32 --- NVIC interrupt
UE像素流,来颗“减肥药”吧!
剑指 Offer 06. 从尾到头打印链表
VESC Benjamin test motor parameters
Installation and use of libjpeg and ligpng
Measurement fitting based on Halcon learning [II] meaure_ pin. Hdev routine
Take you to understand the working principle of lithium battery protection board