Get Update on recent Technology & Programming

Sunday, 29 October 2017

Shell Script to Print Patterns

Posted by   on Pinterest


pattern 1 :
     *  
    * *  
   * * *  
  * * * *  
 * * * * *  
 * * * * *  
  * * * *  
   * * *  
    * *  
     * 
1:  i=1  
2:  while [ $i -le 5 ]  
3:  do  
4:  j=5  
5:  while [ $j -ge $i ]  
6:  do  
7:   echo -n " "  
8:   j=`expr $j - 1`  
9:  done  
10:  j=1  
11:  while [ $j -le $i ]  
12:  do  
13:   echo -n "*"  
14:   echo -n " "  
15:   j=`expr $j + 1`  
16:  done  
17:  echo " "  
18:  i=`expr $i + 1`  
19:  done  
20:  i=1  
21:  while [ $i -le 5 ]  
22:  do  
23:  j=1  
24:  while [ $j -le $i ]  
25:  do  
26:   echo -n " "  
27:   j=`expr $j + 1`  
28:  done  
29:  j=5  
30:  while [ $j -ge $i ]  
31:  do  
32:   echo -n "*"  
33:   echo -n " "  
34:   j=`expr $j - 1`  
35:  done  
36:  echo " "  
37:  i=`expr $i + 1`  
38:  done  

pattern 2 :

1 
22 
333 
4444 
55555 
1:  i=1  
2:  while [ $i -le 5 ]  
3:  do  
4:  j=1  
5:  while [ $j -le $i ]  
6:  do  
7:   echo -n $i  
8:   j=`expr $j + 1`  
9:  done  
10:  echo " "  
11:  i=`expr $i + 1`  
12:  done  
pattern 3 :

1 
12 
123 
1234 
12345 
1:  i=1  
2:  while [ $i -le 5 ]  
3:  do  
4:  j=1  
5:  while [ $j -le $i ]  
6:  do  
7:   echo -n $j  
8:   j=`expr $j + 1`  
9:  done  
10:  echo " "  
11:  i=`expr $i + 1`  
12:  done  

No comments:
Write comments

Hey, we've just launched a new custom color Blogger template. You'll like it -
Join Our Newsletter