\(\begin{array}{cccc}*&&&\\*&*&&\\*&*&*&\\*&*&*&*\\*&*&*&\\*&*&&\\*&&&\end{array}\) 

Write a program that reads a number and displays the above pattern.


Difficulty level
This exercise is mostly suitable for students
#include<stdio.h>
#include<conio.h>

void main()
{
	int N, i, j;
	do{
		printf("Enter N: ");
		scanf("%d",&N);
	}while(N<=0);

	for(i=1; i<2*N; i++)
    	{
		// when i<N, i<N is equal to 0
		// so for the first part, j loops from 1 to i
		// however when i >=N; j loops from 1 to 2N-i
        	for(j=1; j<=( (i/N)*(2*N-2*i)  + i ); j++)
            		printf("*");

       		printf("\n");
    	}

	getch();
}

Back to the list of exercises
Looking for a more challenging exercise, try this one !!
Star pattern 19