I have added numbers to make you understand how we will create this pattern using for loop
- As we know we first see how many lines of code needs to be printed, in this case it is 9 so i will iterate from 1 to n
- Since we will take user input it can be simply n which will be taken from user
- In this example each time stars are being printed 15 times , let that be m
- It will also be taken from user
- So j loop will iterate from 1 to m
Code
#include<stdio.h>
#include<conio.h>
void main(){
int i,j,n,m;
clrscr();
printf("Enter number of lines ");
scanf("%d",&n);
printf("Enter number of lines ");
scanf("%d",&m);
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{
printf("*");
}
printf("\n");
}
getch();
}
Note: scanf is used for taking user input
No comments:
Post a Comment