---------------------------------------------------------------------------
If I say:
X = 5;
PRINT X;
Then the value printed out is
> 5
---------------------------------------------------------------------------
If I say:
X = 5;
PRINT "X";
Then the value printed out is
> X
---------------------------------------------------------------------------
If I say:
X = 5;
PRINT X "is the Biggest";
Then the value printed out is
> 5 is the Biggest
---------------------------------------------------------------------------
If I say:
X = 5;
PRINT "X is the Biggest";
Then the value printed out is
> X is the Biggest
---------------------------------------------------------------------------
Labels
- Ada Lovelace (2)
- Alan Turing (7)
- Algorithms (10)
- Artificial Intelligence (3)
- Charles Babbage (1)
- Design Patterns (1)
- Flowcharts (4)
- History of Computers (8)
- Interaction Design (2)
- Joseph Weizenbaum (1)
- Moore's Law (1)
- Programming (1)
- PseudoCode (5)
Showing posts with label PseudoCode. Show all posts
Showing posts with label PseudoCode. Show all posts
Saturday, January 21, 2012
Assigning a value to a Variable
---------------------------------------------------------------------------
If I want to assign a vaule to a variable, I do the following
X = 5;
we say this as "X gets the value 5".
---------------------------------------------------------------------------
If I want to assign the value of X to a new variable Biggest, I do the following
Biggest = X;
we say this as "Biggest gets the value of X".
---------------------------------------------------------------------------
If I want to add two numbers and print out the result, I do the following
X = 5;
Y = 4;
SumOfNums = X + Y;
The following is incorrect:
X + Y = SumOfNums;
---------------------------------------------------------------------------
If I want to assign a vaule to a variable, I do the following
X = 5;
we say this as "X gets the value 5".
---------------------------------------------------------------------------
If I want to assign the value of X to a new variable Biggest, I do the following
Biggest = X;
we say this as "Biggest gets the value of X".
---------------------------------------------------------------------------
If I want to add two numbers and print out the result, I do the following
X = 5;
Y = 4;
SumOfNums = X + Y;
The following is incorrect:
---------------------------------------------------------------------------
Sunday, January 15, 2012
BubbleSort Pseudocode
---------------------------------------------------------------------------
PROGRAM BubbleSort:
/*===================
DECLARING VARIABLES
===================*/
int ARRAY[N];
int innerloop = 0;
int outerloop = 0;
/*-------------------*/
END.
---------------------------------------------------------------------------
---------------------------------------------------------------------------
PROGRAM Swap (int First, int Second):
/*===================
DECLARING VARIABLES
===================*/
int Temp;
/*-------------------*/
Temp = First;
First = Second;
Second = Temp;
END.
---------------------------------------------------------------------------
PROGRAM BubbleSort:
/*===================
DECLARING VARIABLES
===================*/
int ARRAY[N];
int innerloop = 0;
int outerloop = 0;
/*-------------------*/
WHILE (outerloop < N)
DO WHILE (innerloop < N)
DO IF (A[innerloop] > A[innerloop + 1])
THEN Swap (A[innerloop], A[innerloop + 1]);
END IF;
innerloop++;
END WHILE;
innerloop = 0;
outerloop++;
END WHILE;
/*-------------------*/
END.
---------------------------------------------------------------------------
---------------------------------------------------------------------------
PROGRAM Swap (int First, int Second):
/*===================
DECLARING VARIABLES
===================*/
int Temp;
/*-------------------*/
Temp = First;
First = Second;
Second = Temp;
END.
---------------------------------------------------------------------------
Friday, October 28, 2011
Sample Pseudocode
Hi all,
just to let you know, in terms of Pseudocode, here's an example:
---------------------------------------------------------------------------
PROGRAM ExampleProgram:
/*===================
DECLARING VARIABLES
===================*/
int X;
char Y;
/*-------------------*/
int ARRAY[N];
char ARRAY[N];
/*-------------------*/
int ARRAY[N,M];
char ARRAY[N,M];
/*===================
SELECTION
===================*/
IF (condition)
THEN statements;
ELSE statements;
ENDIF;
/*-------------------*/
CASE (Expression)
Condition1: statements;
Condition2: statements;
Condition3: statements;
Condition4: statements;
:
:
ConditionN: statements;
ENDCASE;
/*===================
ITERATION
===================*/
WHILE (condition)
DO statements;
ENDWHILE;
/*-------------------*/
FOR (X = 1 TO 10)
DO statements;
ENDFOR;
/*-------------------*/
END.
---------------------------------------------------------------------------
Any of these are perfectly fine, and really any other command you like - I can't really just list all the commands that are permitted, otherwise I'd be kinda giving you the answer.
And don't forget to use CamelNotation (aka CamelCase):
just to let you know, in terms of Pseudocode, here's an example:
---------------------------------------------------------------------------
PROGRAM ExampleProgram:
/*===================
DECLARING VARIABLES
===================*/
int X;
char Y;
/*-------------------*/
int ARRAY[N];
char ARRAY[N];
/*-------------------*/
int ARRAY[N,M];
char ARRAY[N,M];
/*===================
SELECTION
===================*/
IF (condition)
THEN statements;
ELSE statements;
ENDIF;
/*-------------------*/
CASE (Expression)
Condition1: statements;
Condition2: statements;
Condition3: statements;
Condition4: statements;
:
:
ConditionN: statements;
ENDCASE;
/*===================
ITERATION
===================*/
WHILE (condition)
DO statements;
ENDWHILE;
/*-------------------*/
FOR (X = 1 TO 10)
DO statements;
ENDFOR;
/*-------------------*/
END.
---------------------------------------------------------------------------
Any of these are perfectly fine, and really any other command you like - I can't really just list all the commands that are permitted, otherwise I'd be kinda giving you the answer.
And don't forget to use CamelNotation (aka CamelCase):
Subscribe to:
Posts (Atom)

