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*/
  }
}

September 5, 2011

Example 9

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



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 */
  }
}

September 2, 2011

Example 7

Task:
Create a program to calculate the number of words.
Example:
Sentence: learn algorithm
Word count: 2


Code:
input sentence

isAnyWord<-F 
num<-0
for a<-1 to Length(sentence), a++
{
  if sentence[a]!= ' ' then isAnyWord <- T //if not space
  if sentence[a] = ' ' then //if space
  {
    if isAnyWord = T then //if previously there was a word, num++
    { 
      num++
      isAnyWord = F
    } 
  }
}

September 1, 2011

Example 6

Task:
Prompted to enter a user id and password if id and password is correct then the user will view the first entry is required, otherwise the process is repeated from the beginning to user id and password are correct.
Code:
id,password : string

begin
repeat
input id 
input password
   until 
   id = 'username' and  password = '123'
   print('You have entered the main page')
end.