Custom Search

Tuesday 15 September 2015

Unix Script to Print Pyramid of Stars


Unix Script for Printing Stars
Here is the simple script in Unix / Linus to print the stars in the form of Pyramid as shown below.
We have used for loop for the same as we use it in C/C++. The read command in the same helps to save the users input for further use. The echo command helps the user to display the data on the screen.

 Print the pyramid of stars
      #!/bin/bash
      echo "pyramid size (1 to 100): "
      read n
      for ( (i=1;i<=n;i++ ) )
      do
for ( (k=i;k<=n;k++ ) )
do
  echo -ne "  "
done
for ( (j=1;j<=i;j++) )
do
  echo -ne "*"
done
for ( (z=1;z<i;z++) )
do
  echo -ne "*"
     done

No comments:

Post a Comment

Laptops