September 7, 2011

Example 10

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 = 1) and (column <= N div 2 + 1) then
    {
      output("*");
    } else if (row = n) and (column >= n div 2 + 1) then
    {
      output("*");
    } else if (column = 1) and (row >= n div 2 + 1) then
    {
      output("*");
    } else if (column = n) and (row <= n div 2 + 1) then
    {
      output("*");
    } else if (column = n div 2 + 1) or (row = n div 2 + 1) then
    {
      output("*");
    } else
    {
      output(" ");
    }
    output("\n"); /*new line*/
  }
}

No comments:

Post a Comment