Q:

Pattern programs in C

0

Pattern programs in C

Pattern programs in C language, showing how to create various patterns of numbers and stars. The programs require nested loops (a loop inside another loop). A design of numerals, stars, or characters is a way of arranging these in some logical manner, or they may form a sequence. Some of these are triangles that have particular importance in mathematics. Some patterns are symmetrical, while others are not. See the complete page for all of them.

    *

   ***

  *****

 *******

 

*********

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

c#include <stdio.h>
int main()
{
  int row, c, n;

  printf("Enter the number of rows in pyramid of stars to print\n");
  scanf("%d", &n);

  for (row = 1; row <= n; row++)  // Loop to print rows
  {
    for (c = 1; c <= n-row; c++)  // Loop to print spaces in a row
      printf(" ");

    for (c = 1; c <= 2*row - 1; c++) // Loop to print stars in a row
      printf("*");

    printf("\n");
  }

  return 0;
}

outputs:

Enter the number of rows in pyramid of stars to print

5

    *

   ***

  *****

 *******

*********

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now