WAP(write a program) to display the following star pattern..
Attachments:
Answers
Answered by
1
Pattern program in C
#include <stdio.h>
int main()
{
int row, c, n, s;
printf("Enter the number of rows in pyramid of stars you wish to see\n");
scanf("%d", &n);
s = n;
for (row = 1; row <= n; row++) // Loop to print rows
{
for (c = 1; c < s; c++) // Loop to print spaces in a row
printf(" ");
s--;
for (c = 1; c <= 2*row - 1; c++) // Loop to print stars in a row
printf("*");
printf("\n");
}
return 0;
}
public class Triangular
{
public static void main(String args[])
{
int n, i, j, space = 1;
System.out.print("Enter the number of rows: ");
Scanner s = new Scanner(System.in);
n = s.nextInt();
space = n - 1;
for (j = 1; j <= n; j++)
{
for (i = 1; i <= space; i++)
{
System.out.print(" ");
}
space--;
for (i = 1; i <= (2 * j - 1); i++)
{
System.out.print("*");
}
System.out.println("");
}
}
}
PLEASE MARK MY ANSWER AS A BRAINLIEST ANSWER.
#include <stdio.h>
int main()
{
int row, c, n, s;
printf("Enter the number of rows in pyramid of stars you wish to see\n");
scanf("%d", &n);
s = n;
for (row = 1; row <= n; row++) // Loop to print rows
{
for (c = 1; c < s; c++) // Loop to print spaces in a row
printf(" ");
s--;
for (c = 1; c <= 2*row - 1; c++) // Loop to print stars in a row
printf("*");
printf("\n");
}
return 0;
}
public class Triangular
{
public static void main(String args[])
{
int n, i, j, space = 1;
System.out.print("Enter the number of rows: ");
Scanner s = new Scanner(System.in);
n = s.nextInt();
space = n - 1;
for (j = 1; j <= n; j++)
{
for (i = 1; i <= space; i++)
{
System.out.print(" ");
}
space--;
for (i = 1; i <= (2 * j - 1); i++)
{
System.out.print("*");
}
System.out.println("");
}
}
}
PLEASE MARK MY ANSWER AS A BRAINLIEST ANSWER.
sambitpatra8272:
Please do it in java . I request
Answered by
8
Answer:
We will create different patterns or a geometrical shape such as triangle, square, etc. We are going to cover the following patterns.
Similar questions