Print stars like a Triangle in C++

C++ Program to print stars in Triangle Form

Source code :


#include <iostream>

using namespace std;

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

Output :

        
        
        
        
        * 

Output :


                

Comments :