Flowchart Examples and Solutions for Programming

revision n.w
1 / 35
Embed
Share

Explore flowchart examples and solutions for programming concepts such as calculating Zakat based on user input, finding the sum of natural numbers, and more. Enhance your understanding of pseudocode and flowcharts through practical illustrations.

  • Flowcharts
  • Programming Solutions
  • Pseudocode
  • Zakat Calculation
  • Natural Numbers

Uploaded on | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. Revision 1 Nouf almunyif

  2. Pseudocode & Flowcharts 2 Nouf almunyif

  3. Example 1 3 Draw a flowchart for a program that calculates the Zakat, where the user enter the amount of money then the program show the zakat. Zakat =(2.5/100) * amount. Zakat is not calculated if the amount is less than 1000 S.R Nouf almunyif

  4. Solution 4 Input amount. Processing Check if amount is below 1000 Zakat =0. Check if amount is above 1000 Zakat =(2.5/100) * amount Output Zakat Nouf almunyif

  5. Solution 5 Start Read amount yes no Amount > 1000 Zakat=0. Zakat=(2.5/100)*amount Print Zakat Nouf almunyif End

  6. Example 2 6 Draw a flowchart to find the sum of first 50 natural numbers. 1+2+3+ .. +50 Nouf almunyif

  7. 7 Nouf almunyif

  8. Structure of a .c file 8 Nouf almunyif

  9. 9 Nouf almunyif

  10. input/output 10 Nouf almunyif

  11. Output: If you need to display a string on the screen 11 Nouf almunyif

  12. Input: if you want to read values from the user 12 Nouf almunyif

  13. Data types 13 Nouf almunyif

  14. Declaring different types 14 Nouf almunyif

  15. output 15 Nouf almunyif

  16. Constants 16 Nouf almunyif

  17. Operator precedence 17 Nouf almunyif

  18. Branching if syntax 18 Nouf almunyif

  19. Example 19 Write a code that read x and change its value as follows: If x is even, divide x by 2. If x is odd, multiply x by 3 and subtract 1. Nouf almunyif

  20. 20 Nouf almunyif

  21. 21 Nouf almunyif

  22. Branching if syntax 22 if (testExpression1) { // statements to be executed if testExpression1 is true } else if(testExpression2) { // statements to be executed if testExpression1 is false // and testExpression2 is true } else if (testExpression 3) { // statements to be executed if testExpression1 //and testExpression2 is false and testExpression3 is true } . . else { // statements to be executed if all test expressions are false } Nouf almunyif

  23. example 23 Nouf almunyif

  24. 24 Nouf almunyif

  25. what will be printed if x=5 y=8 25 Nouf almunyif

  26. 26 Nouf almunyif

  27. Modify the previous code to produce the output shown. 27 Nouf almunyif

  28. 28 Nouf almunyif

  29. 29 Nouf almunyif

  30. 30 Nouf almunyif

  31. Conditional operator ?: 31 if condition is true ? then X return value : otherwise Y value; Exercise: Write a code that test whether an integer variable score contains a valid test score. Valid test scores are in the range from 0 to 100. Nouf almunyif

  32. Conditional operator ?: if condition is true ? then X return value : otherwise Y value; 32 Nouf almunyif

  33. switch...case Statement Syntax 33 switch (n) { case constant1: // code to be executed if n is equal to constant1; break; case constant2: // code to be executed if n is equal to constant2; break; . . . default: // code to be executed if n doesn't match any constant } Nouf almunyif

  34. 34 Nouf almunyif

  35. 35 Nouf almunyif

Related


More Related Content