This is the last tutorial for the right angle triangle
patterns. After practising this many programs you may find this program easy to
solve, this pattern have different kind of logic to print numbers.
In the pattern which looks like:
The numbers are arranged in the order say 1 to 5 in one column
then 6 to 9 in second column and so on. So here we need to change the statement
inside the for loop.
As shown in the snap shot of the program in the for loop the
value of k i.e. (the maximum value of line you want in output) is used in the
printf statement. Initially k is set to the value of i, and then it is
incremented by the statement [ k += n-j ]
Here n is the total line say column or row you want in
output here it is 5. J is the column number in which the loop is printing
numbers at some time here let us take j =1 say for example. So k is incremented
to the value n – j so [5 – 1=4] and
k will b 2 at that time as i is incremented in for loop, so now k = 6, so in second row printf
statement will print as 2 6.
Thus how numbers are printed in order.
{ 0 comments ... read them below or add one }
Post a Comment