Pattern Printing coding 14
//If you are visiting this post in mobile then, please use desktop site mode //
CODE NO:- 23
Print the below pattern
Print the below pattern
#LOGIC
Using two inner loop print the first half of the pattern.
Using another two inner loop print the second half of the pattern.
For example: if entered no.of rows are 4 then the first half will contain 4 rows and another half will contain 3 rows.
#Program( In C):
In C language we use ' // ' for Single line comment and /*---*/ for multi line comment
#include<stdio.h>// header file for i/p and o/p
int main()
{
int i,j,a=0,b,n,k;
printf("\n enter no. of rows:");
scanf("%d",&n);
for(i=0;i<n;i++)// loop for printing the upper half of the pattern
{
for(j=0;j<=i;j++)
{
printf("*");
}
printf("\n");
}
for(i=0;i<n-1;i++)// loop for printing the lower half of the pattern
{
for(j=0;j<n-1-i;j++)
{
printf("*");
}
printf("\n");
}
return 0;
}
We got this output by using DEV C++ (IDE)
Comments
Post a Comment