Q. How do I print pyramid of numbers in Bash
Ans.
Before writing bash script lets understand how we going to print this pattern. We do it in two part, first we are going to print part 1 and then we print the part 2. As you can notice from above figure that, in 2nd part we are printing number in reverse order till 1.
#!/bin/bash #Taking input read -p "Enter Number:" number #Outer loop for printing number of rows in pyramid for((row=1;row<=number;row++)) do #Loop for printing required spaces for((spaces=row;spaces<=number;spaces++)) do echo -ne " " done #Loop for printing 1st part for((j=1;j<=row;j++)) do echo -ne "$j" done #Loop for printing 2nd part for((l=(row-1);l>=1;l--)) do echo -ne "$l" done #echo for printing new line echo done
Output
Enjoy :)
If You Liked This Post Please Take a Time To Share This Post
how to print
ReplyDelete1
12
1234
123456
same as
Delete*
**
***
****
for above pyramid we print "row" alphabet.. to get the pyramid asked by you should print the "2nd" alphabet and initiate it by "1".
WTF
Delete#!/bin/bash
Deleteecho "enter the n value"
read n
for((i=1;i<=n;i++))
do
for((j=1;j<=i;j++))
do
echo -n $j " "
done
echo
done
How to print:
ReplyDelete0
0 2
0 2 4
0 2 4 16
0 2 4 16 256
I have posted a relevent answer to your question. Correct me if I'm wrong. Happy to help :P
DeleteI have posted a relevent answer to your question. Correct me if I'm wrong. Happy to help :P
Delete#!/bin/bash
ReplyDeleteread -p "N? : " n
for((i = 0; i < n; i++))
do
k=0
key=0
while((k < $((i+1))))
do
if((k == 0))
then
echo -e "$key \c"
key=2
k=$((k+1))
else
echo -e "$key \c"
key=$(echo "$key^2" | bc)
k=$((k+1))
fi
done
echo " "
done
#!/bin/bash
ReplyDeleteread -p "N? : " n
for((i = 0; i < n; i++))
do
k=0
key=0
while((k < $((i+1))))
do
if((k == 0))
then
echo -e "$key \c"
key=2
k=$((k+1))
else
echo -e "$key \c"
key=$(echo "$key^2" | bc)
k=$((k+1))
fi
done
echo " "
done
How to print 1
Delete22
333
4444
55555
How to print
Delete1
22
333
4444
55555
how to print
ReplyDelete1
12
123
1234
12345
can any one help me print the following pattern :-
ReplyDelete54321
4321
321
21
1
your shell script program is too easy and understand please share more program
ReplyDeletewrite for us
If you are looking for the Software Engineering Help assignment then in this case you can opt for our Essay Writing.we provide the best online assignment help.We also provide law essay help for students across the globe. for more information contact us +16692714848.
ReplyDeleteThanks a lot for the kind of perfect topic I have not a lot of information about it but I have got an extra Yellowstone rip wheeler vest unique info in your unique post.Perfect description you have provided thanks for sharing.
ReplyDeleteHow to print
ReplyDelete0
1 0
2 1 0
3 2 1 0
Write a shell script which will accept the number of row as input and will print the
Deletefollowing output (using loop)
1
2 8
3 12 27
4 16 36 64
The Irritable Bowel Syndrome Treatment Market size was valued at $1,071 million in 2018, and is estimated to reach $2,012 million by 2026, registering a CAGR of 8.2% from 2019 to 2026. Irritable bowel syndrome (IBS) is a common gastrointestinal disorder that affects the large intestine. Signs & symptoms include abdominal pain, bloating, gas, cramping, and constipation or diarrhea. There are three types of irritable bowel syndrome such as IBS with diarrhea (IBS-D), IBS with constipation (IBS-C), and Mixed IBS. Treatment of irritable bowel syndrome consists of stress relief, change in diet, proper medicines, and counselling. Medications available for the treatment of irritable bowel syndrome include rifaximin, eluxadoline, lubiprostone, linaclotide, and others.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteI Just Loved It And It was Perfect superman suit
ReplyDeleteSuch a well-written post! I learned so much from this and can’t wait to apply these tips. If you’re looking for discounts or deals, don’t forget to check out https://offercatcher.com/. It’s a lifesaver!"
ReplyDelete