For beginners in C language it is very important to
understand LOOPING. By understanding how loop works your programming power will
improve to next level.
Many students face problem in looping during coding for big
programs, they got confuse if more loops are involved in a program. So to
eradicate this problem we have tried to clear your concepts as better as we can
do it. Here we have explained all small loops from simple to nested loops.
This tutorial explains use of different loops by making
different patterns of “*”, “alphabets”, “numbers”.
Now let us take one example of such pattern:
This pattern is of “*” which are arranged in a right angle
triangle, so to perform this in program we need to use FOR LOOP. We can use
while loop do while loop also but as you know benefit of using for loop is we
can initialize counter ,its condition and incrementation or decrementation
while other loops only provide condition checking , The coding for this is
given as below in snap shot.
Here nested for loop is used.
First FOR loop execute as many times as you enter the lines
(size) of patterns you want. Here in this example size is 5 so “k=5”, so [for(i=1;i<=k;i++)] starting from 1
to 5 line will be incremented.
Second FOR loop is for printing “*” , here * is printed in
increasing order starting from 1 to ‘k’ (number you have entered) so we have to
increment the variable ‘j’ which is use in loop as
[ for(j=1;j<=i;j++)]
Here starting from 1 to the number of preceding loop
executes.
Here only one pattern is explained there are minimum 20
patterns only of right angle triangle that can be made by doing little
variation such as printing “alphabets” or
“numbers” also applying different ideas of printing numbers and
alphabets. To apply that variation
all we have to do is just change the printf
statement according to our purpose, Other patterns that can be made are:
This is an introductory tutorial which explains only one
pattern but we will soon provide all other patterns’ tutorials explaining all
programs to its detail. Till then try it yourself, if you are facing any
problem in making above shown patterns just comment its pattern code and we
will try to sort you out your problem.
{ 0 comments ... read them below or add one }
Post a Comment