SlideServe
Menu
Préférences
© SlideServe · v2026

Pseudocode Examples

ron avatar
21 diapositives · 958 Views · Jul 28, 2014
Pseudocode Examples - slide 1
01 / 21Pseudocode Examples
1 / 17

Télécharger la présentation

Pseudocode Examples
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. Pseudocode Examples An algorithm is a procedure for solving a problem in terms of the actions to be executed and the order in which those actions are to be executed. An algorithm is merely the sequence of steps taken to solve a problem. The steps are normally "sequence," "selection, " "iteration," and a case-type statement.

  2. Pseudocode Examples For example, In C, "sequence statements" are imperatives. The "selection" is the "if then else" statement, and the iteration is satisfied by a number of statements, such as the "while," " do," and the "for," while the case-type statement is satisfied by the "switch" statement.

  3. Pseudocode Pseudocode is an artificial and informal language that helps programmers develop algorithms. Pseudocode is a "text-based" detail (algorithmic) design tool. The rules of Pseudocode are reasonably straightforward. All statements showing "dependency" are to be indented. These include while, do, for, if, switch.

  4. Pseudocode Pseudocode A way of expressing algorithms using English phrases and indention to make the steps in the solution explicit

  5. More About Pseudocode We need to express more complicated algorithms Like Washing our Hair

  6. A Algorithm for Hair Step 0: Wet Hair Step 1: Apply shampoo Step 2: Lather Step 3: Rinse Step 4: If (Hair not clean enough) goto Step 1 Step 5: Done

  7. Pseudocode With Pseudocode we can express… Individual steps (Sequential Operations) As Well as Structure… Repetition (Iterations) Selection (Control Operations)

  8. Pseudocode for Adding 3 numbers Step 1) load the sum (0) to the accumulator Step 2) Read first number from the keyboard Step 3) Add first number to the accumulator Step 4) Read second number from the keyboard Step 5) Add second number to the accumulator Step 6) Read third number from the keyboard Step 7) Add third number to the accumulator Step 8) Store accumulator back to the sum Step 9) Display the sum Step 10) Stop

  9. IN-CLASS LAB Your turn: Find the average of 4 numbers and display it.

  10. Your turn:Find the average of 4 numbers and display it. Answer : There are many ways to answer this correctly as long as it is clear you got it right. Ask your friend to check it. input 4 numbers sum = add numbers together avg = sum / 4 print avg

  11. Counting upRead number n and print the integerscounting up to n. In-Class Lab

  12. Counting upRead number n and print the integerscounting up to n. Read n. Initialize i to 1. while i<=n , do: Write i. (Print/Display i) increment i. (i=i+1) end while Stop.

  13. Summing consecutive integersRead number n and print the sum of theintegers up to n,1 + 2 + ……+n In-Class Lab

  14. Summing consecutive integersRead number n and print the sum of theintegers up to n,1 + 2 + ……+n In-Class Lab

  15. Summing consecutive integersRead number n and print the sum of theintegers up to n,1 + 2 + ……+n Read n. Initialize i to 1. Initialize sum to 0. while i<=n, do: Increase sum by i. (sum=sum+i) Increment i. end while Write sum. Stop.

  16. Power of twoRead number n and print 2n. In-Class Lab

  17. Power of twoRead number n and print 2n. Read n . Initialize power to 1. Repeat n times: Double power. End repeat Write power Stop.

  18. MultiplicationRead number m and n and print m x n In-Class Lab

  19. MultiplicationRead number m and n and print m x n Read m. Read n. Initialize multi to 0. Set multi to m * n Print multi. Stop

  20. Summing upSumming consecutive integers from 1 to 100 In-Class Lab

  21. Summing upSumming consecutive integers from 1 to 100 Set the value of sum to 0 Set the value of x to 1 While x is less than or equal to 100 Add x to sum (sum=sum+x) Add 1 to the value of x (x=x+1) Print the value of sum Stop