5种shell乘法口诀

简介:
1
2
3
4
5
6
7
8
#!/bin/bash
for  in  $( seq  1 9);
do
         for  in  $( seq  1 ${i})
         do
                 echo  -n  -e  "${j}x${i}=$(expr ${i} \* ${j})\t"
         done
done
1
1x1=1   1x2=2   2x2=4   1x3=3   2x3=6   3x3=9   1x4=4   2x4=8   3x4=12  4x4=16 1x5=5    2x5=10  3x5=15  4x5=20  5x5=25  1x6=6   2x6=12  3x6=18  4x6=24  5x6=30 6x6=36   1x7=7   2x7=14  3x7=21  4x7=28  5x7=35  6x7=42  7x7=49  1x8=8   2x8=16 3x8=24   4x8=32  5x8=40  6x8=48  7x8=56  8x8=64  1x9=9   2x9=18  3x9=27  4x9=36 5x9=45   6x9=54  7x9=63  8x9=72  9x9=81


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/bin/bash
for ((i=1;i<=9;i++))
do
     for ((j=1;j<=i;j++))
     do
     let  A=i*j
     echo  -n  "$(i)x$j=$A "
     done
echo  " "
done
1x1=1
2x1=2 2x2=4
3x1=3 3x2=6 3x3=9
4x1=4 4x2=8 4x3=12 4x4=16
5x1=5 5x2=10 5x3=15 5x4=20 5x5=25
6x1=6 6x2=12 6x3=18 6x4=24 6x5=30 6x6=36
7x1=7 7x2=14 7x3=21 7x4=28 7x5=35 7x6=42 7x7=49
8x1=8 8x2=16 8x3=24 8x4=32 8x5=40 8x6=48 8x7=56 8x8=64
9x1=9 9x2=18 9x3=27 9x4=36 9x5=45 9x6=54 9x7=63 9x8=72 9x9=81


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#!/bin/bash
for  (( i=1; i<=9; i++ ))
do
         for  (( j=1; j<=i; j++ ))
         do
                 printf  '%dx%d=%-3d'  $i $j $(($i*$j))
         done
         echo
done
1*1=1
1*2=2 2*2=4
1*3=3 2*3=6 3*3=9
1*4=4 2*4=8 3*4=12 4*4=16
1*5=5 2*5=10 3*5=15 4*5=20 5*5=25
1*6=6 2*6=12 3*6=18 4*6=24 5*6=30 6*6=36
1*7=7 2*7=14 3*7=21 4*7=28 5*7=35 6*7=42 7*7=49
1*8=8 2*8=16 3*8=24 4*8=32 5*8=40 6*8=48 7*8=56 8*8=64
1*9=9 2*9=18 3*9=27 4*9=36 5*9=45 6*9=54 7*9=63 8*9=72 9*9=81


1
2
3
4
5
6
7
8
9
10
11
12
13
#!/bin/bash
for  in  {1..9}
do
   for  ((j=1;j<=9;j++))
    do
     echo  -n  "$j*$i=$(($j*$i)) "
       if  [ $j - ge  $i ]
       then
        echo  -e  '\n'
         break
       fi
    done
done
1
2
3
4
5
6
7
8
9
1x1=1
2x1=2  2x2=4
3x1=3  3x2=6  3x3=9
4x1=4  4x2=8  4x3=12 4x4=16
5x1=5  5x2=10 5x3=15 5x4=20 5x5=25
6x1=6  6x2=12 6x3=18 6x4=24 6x5=30 6x6=36
7x1=7  7x2=14 7x3=21 7x4=28 7x5=35 7x6=42 7x7=49
8x1=8  8x2=16 8x3=24 8x4=32 8x5=40 8x6=48 8x7=56 8x8=64
9x1=9  9x2=18 9x3=27 9x4=36 9x5=45 9x6=54 9x7=63 9x8=72 9x9=81


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#!/bin/bash
declare  -i i=1
declare  -i j
while  (( $i <= 9 ))
do
    j=1
    while  (( $j <= $i ))
    do
       let  prod=$i*$j
       printf  "%d*%d=%2d"  $j $i $prod
       let  j=$j+1
    done
    printf  "/n"
    let  i++
done
本文转自 cs312779641 51CTO博客,原文链接:http://blog.51cto.com/chenhao6/1337466
相关文章
|
19小时前
|
Shell Linux 编译器
C语言,Linux,静态库编写方法,makefile与shell脚本的关系。
总结:C语言在Linux上编写静态库时,通常会使用Makefile来管理编译和链接过程,以及Shell脚本来自动化构建任务。Makefile包含了编译规则和链接信息,而Shell脚本可以调用Makefile以及其他构建工具来构建项目。这种组合可以大大简化编译和构建过程,使代码更易于维护和分发。
12 5
|
1天前
|
Shell 程序员 数据安全/隐私保护
shell 脚本 if-else判断 和流程控制 (基本语法|基础命令)
shell 脚本 if-else判断 和流程控制 (基本语法|基础命令)
|
1天前
|
存储 Shell C语言
shell脚本 编程 变量 基本入门(详解)
shell脚本 编程 变量 基本入门(详解)
|
1天前
|
Shell Linux 编译器
C语言,Linux,静态库编写方法,makefile与shell脚本的关系。
总结:C语言在Linux上编写静态库时,通常会使用Makefile来管理编译和链接过程,以及Shell脚本来自动化构建任务。Makefile包含了编译规则和链接信息,而Shell脚本可以调用Makefile以及其他构建工具来构建项目。这种组合可以大大简化编译和构建过程,使代码更易于维护和分发。
9 3
|
7天前
|
弹性计算 运维 监控
|
7天前
|
存储 弹性计算 运维
自动化收集员工信息的Shell脚本
【4月更文挑战第30天】
10 0
|
8天前
|
弹性计算 运维 Shell
使用shell 脚本打印图形3
【4月更文挑战第29天】
20 0