
Flowchart Examples and Solutions for Programming
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.
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
Revision 1 Nouf almunyif
Pseudocode & Flowcharts 2 Nouf almunyif
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
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
Solution 5 Start Read amount yes no Amount > 1000 Zakat=0. Zakat=(2.5/100)*amount Print Zakat Nouf almunyif End
Example 2 6 Draw a flowchart to find the sum of first 50 natural numbers. 1+2+3+ .. +50 Nouf almunyif
7 Nouf almunyif
Structure of a .c file 8 Nouf almunyif
9 Nouf almunyif
input/output 10 Nouf almunyif
Output: If you need to display a string on the screen 11 Nouf almunyif
Input: if you want to read values from the user 12 Nouf almunyif
Data types 13 Nouf almunyif
Declaring different types 14 Nouf almunyif
output 15 Nouf almunyif
Constants 16 Nouf almunyif
Operator precedence 17 Nouf almunyif
Branching if syntax 18 Nouf almunyif
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 Nouf almunyif
21 Nouf almunyif
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
example 23 Nouf almunyif
24 Nouf almunyif
what will be printed if x=5 y=8 25 Nouf almunyif
26 Nouf almunyif
Modify the previous code to produce the output shown. 27 Nouf almunyif
28 Nouf almunyif
29 Nouf almunyif
30 Nouf almunyif
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
Conditional operator ?: if condition is true ? then X return value : otherwise Y value; 32 Nouf almunyif
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 Nouf almunyif
35 Nouf almunyif