How can you display the following patterns?
Answers
Explanation:
I am sorry for my bad writing I hope you understand
Answer:
For Star pattern =>
#include <stdio.h>
int main()
{
int x,y;
printf("Enter the number of rows");
scanf("%d",&y);
x=y;
for(int i=1;i<=y;i++)
{
for(int j=1;j<i;j++)
{
printf(" ");
}
for(int k=1;k<=x;k++)
{
printf("*");
}
x--;
printf("\n");
}
return 0;
}
Above code will ask you how many rows to print of stars.
For Number pattern =>
#include <stdio.h>
int main()
{
int i,j,n;
printf("Enter the number of rows:");
scanf("%d",&n);
for(i = 1; i <= n; i++)
{
int currentNum = 2* i - 1;
for(j = 1; j <= i; j++)
{
printf("%d",currentNum);
currentNum = currentNum - 2;
}
printf("\n");
}
}
Above code will ask you how many rows to print of the numbers you want to print.