Print stars like a Triangle in C

C Program to print stars in Triangle Form

Source code :


#include <stdio.h>

int main()
{
    int i,sp,k=0;
    
    for(i=1;i<=5;++i)
    {
        for(sp=1;sp<=5-i;++sp)
        {
           printf("  ");
        }
        while(k!=2*i-1)
        {
           printf("* ");
           ++k;
        }
        k=0;
        printf("\n");
    }
    return 0;
}

Output :

        
        
        
        
        * 

Output :


                

Comments :