Print Reverse nxn multiplication table

Source: Internet
Author: User
Tags define function

I. Experimental requirements:

    • Given any one of the characters N (n>0), then print the reverse multiplication table of the NXN.

two. Problem solving :

#/!bin/bash
#

#define Function
Nxn_fun () {

Local i=$1 #定义一个局部变量i控制外层循环
While [$i-ge 1];d o
Local j= $i #定义一个局部变量j控制内层循环
While [$j-ge 1];d o
ECHO-E-N "$i * $j =$[i*j]\t"
Let j--
Done
echo #换行
Let i--
Done
}

#main
Flag=$ (echo "$" | sed ' s/[0-9]//g ' | wc-c) #判断脚本参数是整型还是字符

if [! $#-eq 1];then #判断脚本参数个数
echo ">_<| | | It's awkward ~!!! usage:$ (basename) num. "
Exit 5
elif [! $Flag-eq 1];then #Flag值不等于1则给定的脚本参数为字符型

echo ">_<| | | It's awkward ~!!! usage:$ (basename) num. " #表情符号还是挺不错的

Exit 5

Fi

Nxn_fun $
[$?-eq 0]&&echo "Print $1*$1 multiplication table complete (^_^) hehe" | | echo "Function execution error, please check ... (B_d) Wearing a pair of glasses " #函数执行成功则打印乘法表

Three. Experimental results:

Four. Experimental thinking?

1. How can I tell if the parameters given by the script are characters or integers, there is no other way?

2. The outer while loop parameters can be directly to $, how to change, can't why?

Five. The comforting code snippet is:

Flag=$ (echo "$" | sed ' s/[0-9]//g ' | wc-c)

Print Reverse nxn multiplication table

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.