際際滷

際際滷Share a Scribd company logo
Algorithms and
Programming
Easier than you thought
 First you have to find a solution to a
problem
 Example: Find the sum of two numbers
 Formulate a solution in your own words
Your answer may look like this:
 Take two numbers
 Add them
 Display the answer
(this is your solution in words)
Algorithm
in words in pseudocode
 Take two numbers
 Add them
 Display the answer
Enter num1
Enter num2
Sum  num1 + num2
Write sum
Programming (Turbo Pascal)
 Enter num1
 Enter num2
 Sum  num1 + num2
 Write sum
Writeln(Please enter a
number.);
Readln(num1);
Writeln(Please enter another
number.);
Readln(num2);
Sum := num1 + num2 ;
Writeln(The sum of  ,num1, and
 , num2, is  ,sum, .)
In Turbo Pascal, your program should look like this:
Program sum1;
uses crt;
var
num1, num2, sum: integer;
begin
clrscr;
writeln(Please enter a number.);
readln(num1);
writeln(Please enter another number.);
readln(num2);
sum:= num1 + num2;
writeln(The sum of  ,num1,  and  , num2,  is  ,sum, .) ;
readln
end.
Quite easily done!
THE END
omaartens@nied.edu.na

More Related Content

Algorithms and programs - an introduction

  • 2. First you have to find a solution to a problem Example: Find the sum of two numbers Formulate a solution in your own words
  • 3. Your answer may look like this: Take two numbers Add them Display the answer (this is your solution in words)
  • 4. Algorithm in words in pseudocode Take two numbers Add them Display the answer Enter num1 Enter num2 Sum num1 + num2 Write sum
  • 5. Programming (Turbo Pascal) Enter num1 Enter num2 Sum num1 + num2 Write sum Writeln(Please enter a number.); Readln(num1); Writeln(Please enter another number.); Readln(num2); Sum := num1 + num2 ; Writeln(The sum of ,num1, and , num2, is ,sum, .)
  • 6. In Turbo Pascal, your program should look like this: Program sum1; uses crt; var num1, num2, sum: integer; begin clrscr; writeln(Please enter a number.); readln(num1); writeln(Please enter another number.); readln(num2); sum:= num1 + num2; writeln(The sum of ,num1, and , num2, is ,sum, .) ; readln end.