USING FOR LOOP THE CODE TO DISPLAY THE PATTERN OF FORWARD ARROW
Amit Waghmare
September 22, 2018
Hello, In this blog we learn how to print the forward pattern using for loop. In C language the for loop is very useful, for loop include initialization, condition and incrementation. So by using this loop we print the pattern.
USING FOR LOOP THE CODE TO DISPLAY THE PATTERN:
#include<stdio.h>
#include<conio.h>
int main()
{int i, j, n;
printf ("ENTER THE NUMBER TO DISPLAY PATTERN ");
scanf ("%d",&n);
for(i=1; i<=n; i++)
{for(j=1; j<=i; j++)
{printf("♥ ");
}
printf("\n");
}
{ for(i=1; i<=n; i++)
{for(j=i; j<n; j++)
{printf("♥ ");
}
printf("\n");
}}
getch();
}
EXPLANATION:
By using the concept of for loop we print the pattern. First we set the initial value of 'i' i.e. i=1. then it checks the condition i.e. i<=n, n is the value given by the user. then control goes to next statement i.e. in next for loop and we set the initial value of j=1 and check the condition and print ♥.
The execution goes out of the loop when the condition returns false. \n is use to print the statement at next line. So below we see the output of the given code.
Also, we create other pattern using for loop, while loop or using if statement.
OUTPUT:
When inputted is 5
♥
♥ ♥
♥ ♥ ♥
♥ ♥ ♥ ♥
♥ ♥ ♥ ♥ ♥
♥ ♥ ♥ ♥
♥ ♥ ♥
♥ ♥
♥
In this code I'm using the ♥ sign you will use any sign. If you have any problem or question about this blog then write your doubt in the comment box.
Friends in next blog I will teach you another patterns.
USING FOR LOOP THE CODE TO DISPLAY THE PATTERN OF FORWARD ARROW
Reviewed by Amit Waghmare
on
September 22, 2018
Rating: