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

Write a program that reads an integer x and then prints on the screen a triangle of x lines of stars. 


Difficulty level
Video recording
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<=N; i++)
    	{
        	 for(j=i; j<N; j++)
            		printf(" ");

        	for(j=1; j<=(2*i-1); j++)
            		if(i==N || j==1 || j==(2*i-1))
                		printf("*");
            		else
                		printf(" ");

       		printf("\n");
    	}

	getch();
}

Back to the list of exercises
Looking for a more challenging exercise, try this one !!
Kruskal Algorithm - Minimal Spanning Tree