September 3, 2011

Example 8

Task:
Create a program that ask for input integers n with the following provisions:
if  n = 5


Output :
   *
   *
*****
   *
   *

Code:
for row <-- 1 to N do
{
  for column <-- 1 to N do
  {
    if (row = N div 2 + 1) or (column = N div 2 + 1) then
    {
      output("*");
    } else {
      output(" ");
    }
    output("\n"); /* new line */
  }
}

No comments:

Post a Comment