Hello coders! Hows it going? Today we'll see a basic simple shell script to print a triangle using asterisk * only. Here's the code to do that :
You see basically, all we are doing is append a * to itself recursively. Here we are using a basic for-loop to print a triangle of height 10. You can change the height as per your requirement, as needed.
Output :
Cheers!
#!/bin/bash
# Simple program to print a triangle using * of height 10
star="*"
for i in {1..10}
do
echo "$star";
star="$star *"
done
You see basically, all we are doing is append a * to itself recursively. Here we are using a basic for-loop to print a triangle of height 10. You can change the height as per your requirement, as needed.
Output :
*
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * * * *
* * * * * * * *
* * * * * * * * *
* * * * * * * * * *
Cheers!
No comments:
Post a Comment