star's outpud

how to output diamond shape, using a symbol of asterisk.
using a nested for loop.
We don't do people's homework for them, but if you take a stab at it and get stuck we may be able to point you on your way.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
int hashSize = 3;
for( int i = 0; i < hashSize ; i ++)
{
    for( int j = 0; j < hashSize ; j ++)
    {
        if( i % 2 ^ j % 2)
        {
            cout << (char)(0x04);
        }
        else
        {
            cout << "*";
        }
    }
    cout << endl;
}
Last edited on
Topic archived. No new replies allowed.