Thursday, October 6, 2011

Print Triangle of Numbers using shell script in Linux/unix

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

Enjoy :)

2 comments:

Unknown said...

where is the output ?

Anonymous said...

Hi therе! I coulɗ have sworn I've been to уour blog beore Ьut aftrr
browsing thrοugh sokme ⲟf the posts I realized іt'ѕ neԝ to me.
Anyways, I'm defіnitely һappy Ι stumbled uρon it and I'll Ьe book-marking it ɑnd checking ƅack frequently!

Post a Comment