just a small doubt the there are two variables used for increasing and decreasing the values ( var and cnt ). both of them are increasing/decreasing the values as far ive understood (i.e 34543) then what is the difference between the two… im a beginner so i get stuck im some silly doubts : (
Pattern pyramin
hello @bhavaysinghal
cnt is just a counter which we have used to count i values (from 1 to i )
and val is value that we want to print (starting from i )
sorry but can you explain with an example if possible it will be more easier for me to understand
let say i=3
then total 2*i-1 values will be there in the row (i.e 5)
now val variable will be intialised with i.
and cnt with 1.
then loop will iterate for i times (i.e cnt=1,cnt=2,cnt=3) and will print i values. (i.e val=3, val=4,val=5)
now after the loop val variable will contain 6 but we want 4 hence we have written val-=2 in the code.
now in second loop cnt will again initialised with 1 and loop will run i-1 times (i,e cnt=1,cnt=2)
and i-1 values will be print (i,e val=4,val=3)
those i value will be