making triangle pattern with character

Hi guys !
I am supposed to write a program that can form the folowing shape:

(N=5)
ssssO
sssKK
ssOOO
sKKKK
OOOOO

( where s is the space )


and here is the code that my friend told me, but it didn't run when I tried it. And can you please give me some explanation on how the code is formed pleaseeee !!
Thx so much
P/s: sorry i'm just a beginner.



#include <iostream>
using namespace std;
int main()
{
int N;
cin >>N;

if(N<=0)
{ cout << "Wrong value" <<endl;
return 1;
}
for (int i=1; i<=N; i++)
{
for (intj =0; j< N-1;j++)
{
cout << " ";
}
if (i%2 ==0)
{
for ( int j=0;j<i ; j++)
cout << "K";
cout <<endl;
}
else
{

for ( int j=0;j<i ; j++)
cout << "O";
cout <<endl;
}
}
return 0;
}
Last edited on
Topic archived. No new replies allowed.