06 October 2011

Print Triangle of Numbers using shell script in Linux/unix

Leave a Comment

Q. How do I write Shell Script to print triangle of Numbers


Ans:

#!/bin/bash
for((i=1;i<=5;i++))
do
for((k=1;k<=(5-i);k++))
do
echo -e " \c "
done
for((j=1;j<=i;j++))
do
echo -e " $j \c"
done
echo -e "\n"
done


Output


shell script to print triangle of a number

Enjoy :)


If You Liked This Post Please Take a Time To Share This Post

You May Also Like...

0 comments:

Post a Comment