C Program to Print W Star Pattern

Write a C program to print W star pattern using for loop. In this code, the printingStars function iterate and prints the stars, and the printingSpaces prints the spaces to print the W shape.

#include <stdio.h>

void printingStars(int rows)
{
	for (int i = 0; i < rows; ++i)
	{
		printf("*");
	}
}
void printingSpaces(int rows)
{
	for (int i = 0; i < rows; ++i)
	{
		printf(" ");
	}
}

int main()
{
	int rows;

	printf("Enter W Shape Star Pattern Rows = ");
	scanf("%d", &rows);

	printf("Printing W Shape Pattern\n");
	for (int i = 0; i < rows; i++)
	{
		printingStars(i + 1);
		printingSpaces(rows - i - 1);
		printingStars(rows - i + 1);
		printingSpaces(2 * i);
		printingStars(rows - i);
		printingSpaces(rows - i - 1);
		printingStars(i + 1);
		printf("\n");
	}
}
C Program to Print W Star Pattern

This program uses a while loop to display the W star pattern.

#include <stdio.h>

void printingStars(int rows)
{
	int i = 0;
	while (i < rows)
	{
		printf("*");
		++i;
	}
}
void printingSpaces(int rows)
{
	int i = 0;
	while (i < rows)
	{
		printf(" ");
		++i;
	}
}

int main()
{
	int rows;

	printf("Enter W Shape Star Pattern Rows = ");
	scanf("%d", &rows);

	printf("\n");
	int i = 0;
	while (i < rows)
	{
		printingStars(i + 1);
		printingSpaces(rows - i - 1);
		printingStars(rows - i + 1);
		printingSpaces(2 * i);
		printingStars(rows - i);
		printingSpaces(rows - i - 1);
		printingStars(i + 1);
		printf("\n");
		i++;
	}
}
Enter W Shape Star Pattern Rows = 12

*           *************************           *
**          ************  ***********          **
***         ***********    **********         ***
****        **********      *********        ****
*****       *********        ********       *****
******      ********          *******      ******
*******     *******            ******     *******
********    ******              *****    ********
*********   *****                ****   *********
**********  ****                  ***  **********
*********** ***                    ** ***********
**************                      *************

In this example, the WStars function allows entering any character and prints the W pattern of a given character.

#include <stdio.h>

void printingWStars(int rows, char ch)
{
	for (int i = 0; i < rows; ++i)
	{
		printf("%c", ch);
	}
}

void printingWSpaces(int rows)
{
	for (int i = 0; i < rows; ++i)
	{
		printf(" ");
	}
}

int main()
{
	int rows;
	char ch;

	printf("Enter Character = ");
	scanf("%c", &ch);

	printf("Enter Rows = ");
	scanf("%d", &rows);

	printf("\n");
	for (int i = 0; i < rows; i++)
	{
		printingWStars(i + 1, ch);
		printingWSpaces(rows - i - 1);
		printingWStars(rows - i + 1, ch);
		printingWSpaces(2 * i);
		printingWStars(rows - i, ch);
		printingWSpaces(rows - i - 1);
		printingWStars(i + 1, ch);
		printf("\n");
	}
}
Enter Character = @
Enter Rows = 16

@               @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@               @
@@              @@@@@@@@@@@@@@@@  @@@@@@@@@@@@@@@              @@
@@@             @@@@@@@@@@@@@@@    @@@@@@@@@@@@@@             @@@
@@@@            @@@@@@@@@@@@@@      @@@@@@@@@@@@@            @@@@
@@@@@           @@@@@@@@@@@@@        @@@@@@@@@@@@           @@@@@
@@@@@@          @@@@@@@@@@@@          @@@@@@@@@@@          @@@@@@
@@@@@@@         @@@@@@@@@@@            @@@@@@@@@@         @@@@@@@
@@@@@@@@        @@@@@@@@@@              @@@@@@@@@        @@@@@@@@
@@@@@@@@@       @@@@@@@@@                @@@@@@@@       @@@@@@@@@
@@@@@@@@@@      @@@@@@@@                  @@@@@@@      @@@@@@@@@@
@@@@@@@@@@@     @@@@@@@                    @@@@@@     @@@@@@@@@@@
@@@@@@@@@@@@    @@@@@@                      @@@@@    @@@@@@@@@@@@
@@@@@@@@@@@@@   @@@@@                        @@@@   @@@@@@@@@@@@@
@@@@@@@@@@@@@@  @@@@                          @@@  @@@@@@@@@@@@@@
@@@@@@@@@@@@@@@ @@@                            @@ @@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@                              @@@@@@@@@@@@@@@@@

About Suresh

Suresh is the founder of TutorialGateway and a freelance software developer. He specialized in Designing and Developing Windows and Web applications. The experience he gained in Programming and BI integration, and reporting tools translates into this blog. You can find him on Facebook or Twitter.