Shell Script Exercise II

Source: Internet
Author: User

Print 99 multiplication table

#for Statement Format

#!/bin/bash

for ((a = 1; a <= 9; a++))

Do

for ((b=1; b<= $a; b++))

Do

Let Sum=b*a

Echo-ne "$a * $b = $sum \ t"

Done

echo ""

Done

#while Statement Format

#!/bin/bash

A=1

While [$a-le 9]

Do

B=1

While [$b-le $a]

Do

Let sum= $a * $b

Echo-ne "$a * $b = $sum \ t"

Let b++

Done

echo ""

Let a++

Done

Print equilateral triangle

#for statement format, positive triangle

#!/bin/bash

For ((i=1;i<=9;i++))

Do

for ((a=9; a>= $i; a--))

Do

Echo-n ""

Done

for ((b=1; b<=i; b++)

Do

Echo-n "$i"

Done

echo ""

Done

#while statement format, inverted triangle

#!/bin/bash

I=8

While [$i-ge 1]

Do

A=9

While [$a-ge $i]

Do

Echo-n ""

Let a--

Done

B=1

While [$b-le $i]

Do

Echo-n "$i"

Let b++

Done

echo ""

Let i--

Done

Print Diamond

#while Statement Format

#!/bin/bash

I=1

While [$i-le 9]

Do

A=9

While [$a-ge $i]

Do

Echo-n ""

Let a--

Done

B=1

While [$b-le $i]

Do

Echo-n "$i"

Let b++

Done

c=2

While [$c-le $i]

Do

Echo-n "$i"

Let C + +

Done

echo ""

Let i++

Done

I=8

While [$i-ge 1]

Do

A=9

While [$a-ge $i]

Do

Echo-n ""

Let a--

Done

B=1

While [$b-le $i]

Do

Echo-n "$i"

Let b++

Done

c=2

While [$c-le $i]

Do

Echo-n "$i"

Let C + +

Done

echo ""

Let i--

Done

#for Statement Format

for (i=9; i>0; i--)

Do

for ((a=1; a<= $i; a++))

Do

Echo-n ""

Done

for ((b=9; b>= $i; b--))

Do

Echo-n "$i"

Done

for ((c=8; c>= $i; c--))

Do

Echo-n "$i"

Done

echo ""

Done

for ((i=2; i<=9; i++)

Do

for ((a=1; a<= $i; a++))

Do

Echo-n ""

Done

for ((b=9; b>= $i; b--))

Do

Echo-n "$i"

Done

for ((c=8; c>= $i; c--))

Do

Echo-n "$i"

Done

echo ""

Done


Shell Script Exercise II

Related Article

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.