Q. write a C program for following number pyramid and also write down algorithm:
1234554321
1234__4321
123____321
12______21
1________1
Ans.
C program for above number pyramid structure:
click here
Algorithm for above number pyramid as:
[procedure of number pyramid]
step1: Start
step2: Read number num
step3: [initialize]
r=1
step4: Repeat step 4 to 21 until num>=1
step5: [initialize]
c=1
step6: Repeat step 6 to 8 until c<=num
step7: print value of c
step8: c=c+1
[end of step6 loop]
step9: [initialize]
sp=r
step10: Repeat step 10 to 12 until sp>1
step11: print _
step12: sp=sp-1
[end of step10 loop]
step13: [initialize]
sp=r
step14: Repeat step 14 to 16 until sp>1
step15: print _
step16: sp=sp-1
[end of step14 loop]
step17: [initialize]
c=1
step18: Repeat step 18 to 20 until c>=1
step19: print value of c
step20: c=c-1
[end of step18 loop]
step21: Go to next line
[end of step4 loop]
step22: Stop
[end procedure of number pyramid]
1234554321
1234__4321
123____321
12______21
1________1
Ans.
C program for above number pyramid structure:
click here
Algorithm for above number pyramid as:
[procedure of number pyramid]
step1: Start
step2: Read number num
step3: [initialize]
r=1
step4: Repeat step 4 to 21 until num>=1
step5: [initialize]
c=1
step6: Repeat step 6 to 8 until c<=num
step7: print value of c
step8: c=c+1
[end of step6 loop]
step9: [initialize]
sp=r
step10: Repeat step 10 to 12 until sp>1
step11: print _
step12: sp=sp-1
[end of step10 loop]
step13: [initialize]
sp=r
step14: Repeat step 14 to 16 until sp>1
step15: print _
step16: sp=sp-1
[end of step14 loop]
step17: [initialize]
c=1
step18: Repeat step 18 to 20 until c>=1
step19: print value of c
step20: c=c-1
[end of step18 loop]
step21: Go to next line
[end of step4 loop]
step22: Stop
[end procedure of number pyramid]
No comments:
Post a Comment