C Program to Print Right Arrow Star Pattern

Write a C Program to Print the Right Arrow Star Pattern using for loop. In this example, we used nested for loop and the If else statement to print the stars in the right arrow pattern.

#include<stdio.h>
int main()
{
 	int i, j, rows; 
 	printf("Enter Right Arrow Star Pattern Rows =  ");
 	scanf("%d", &rows);

    printf("Right Arrow Star Pattern\n");
	for(i = 1; i <= rows; i++)
	{
        for(j = 1; j <= rows; j++)
        {
            if(j < i)
            {
                printf(" ");
            }
            else
            {
                printf("*");
            }
        }
		printf("\n");
	}

    for(i = 1; i <= rows; i++)
	{
		for(j = 1; j <= rows; j++)
		{
            if(j < rows - i)
            {
                printf(" ");
            }
            else
            {
                printf("*");
            }		
		}
		printf("\n");
	}
 	return 0;
}
C Program to Print Right Arrow Star Pattern

In this example, we altered the for loop a bit to property print the right arrow.

#include<stdio.h>
int main()
{
 	int i, j, rows; 
 	printf("Enter Right Arrow Star Pattern Rows =  ");
 	scanf("%d", &rows);

    printf("Right Arrow Star Pattern\n");
	for(i = 1; i < rows; i++)
	{
        for(j = 1; j <= (2 * i - 2); j++)
        {
            printf(" ");
        }
        for(j = i; j <= rows; j++)
        {
            printf("*");
        }
		printf("\n");
	}

    for(i = 1; i <= rows; i++)
	{
		for(j = 1; j <= (2 * rows - 2 * i); j++)
		{
            printf(" ");
        }
        for(j = 1; j <= i; j++)
        {
            printf("*");
		}
		printf("\n");
	}
 	return 0;
}
Enter Right Arrow Star Pattern Rows =  6
Right Arrow Star Pattern
******
  *****
    ****
      ***
        **
          *
        **
      ***
    ****
  *****
******

In this C Program, we replaced the for loop with a while loop to Print Right Arrow Star Pattern. It also allows entering the symbol to print in the right arrow shape.

#include<stdio.h>
int main()
{
 	int i, j, rows;
    char ch;
    
    printf("Symbol to Print Right Arrow =  ");
    scanf("%c", & ch);
    
 	printf("Enter Right Arrow Star Pattern Rows =  ");
 	scanf("%d", &rows);

    printf("Right Arrow Star Pattern\n");
    i = 1;
	while(i < rows)
	{
        j = 1;
        while(j <= (2 * i - 2))
        {
            printf(" ");
            j++;
        }
        j = i;
        while(j <= rows)
        {
            printf("%c", ch);
            j++;
        }
		printf("\n");
        i++;
	}
    i = 1;
    while(i <= rows)
	{
        j = 1;
		while(j <= (2 * rows - 2 * i))
		{
            printf(" ");
            j++;
        }
        j = 1;
        while(j <= i)
        {
            printf("%c", ch);
            j++;
		}
		printf("\n");
        i++;
	}
 	return 0;
}
Symbol to Print Right Arrow =  #
Enter Right Arrow Star Pattern Rows =  6
Right Arrow Star Pattern
######
  #####
    ####
      ###
        ##
          #
        ##
      ###
    ####
  #####
######