SonyExam
Complete the following print program:
*
*.*.
*..*..*..
*...*...*...*...
*....*....*....*....*....
*.....*.....*.....*.....*.....*.....
*...... *...... *...... *...... *...... *...... *......
*....... *....... *....... *....... *....... *....... *....... *.......
Technorati
# Include <stdio. h>
# Define N 8
Int main ()
{
Int I;
Int J;
Int K;
---------------------------------------------------------
|
|
|
---------------------------------------------------------
Return 0;
}
Solution:
First, through the outermost LoopI = [0, N-1]Output from top to bottomNItems'*'.
# Define N 8
For (INT I = 0; I <n; I ++)
{
Putchar ('*');
Cout <Endl;
}
Output result:
Again, the Triangle star is printed through the nested layer of I.
# Define N 8
For (INT I = 0; I <n; I ++)
{
For (Int J = 0; j <= I; j ++)
{
Putchar ('*');
}
Cout <Endl;
}
Result:
Finally, print '.' through the layer-3 Loop of K '.'
For (INT I = 0; I <n; I ++)
{
For (Int J = 0; j <= I; j ++)
{
Putchar ('*');
For (int K = 0; k <I; k ++)
{
Putchar ('.');
}
}
Cout <Endl;
}
Result: