0% found this document useful (0 votes)
2 views

Lecture 4

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Lecture 4

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

Quiz 1

1. Construct a program that calculates the volume of a


cuboid with parameters specified by the user.

2. Generate C code that will output the following


Pseudo code
/* This program is to display the numerical • Programming language (syntax)
value of ASCII character */ free
#include <stdio.h> • Easily understood by the third
party coder
• A draft in a text/descriptive form
int main (void) • Not constraint to specific variables
{ use
char a;
printf(“Enter a character: “);

// Reads character input from the user Start program


scanf(“%c”, &a); Declare a character variable a
// %d displays the integer value of a Enter an ASCII character
character Scan the character into variable a
// %c displays the actual character Print the character and its
printf(“ASCII value of %c = %d", a, a); equivalent numerical value
return 0; End program
}
Quiz: Write the pseudocode for
the surface_triangle example
/* This program is to calculate the surface • Programming language (syntax)
area of a triangle */ free
#include <stdio.h> • Easily understood by the third
party coder
• A draft in a text/descriptive form
int main (void) • Not constraint to specific variables
{ use
/* declare the variables as integers */
Start program
int b,h,surface;
Set base equals 4
/* define the variables */
Set height equals 1
b = 4; /* base */
Calculate surface triangle
h = 1; /* height */
using equation ½ times
surface = b*h/2;
base times height
/* display the value of surface */
Display the surface triangle
printf("The surface of triangle is: %d",
value
surface);
End program
return 0;
}
Quiz
1. Construct a program that calculates the volume of a
cuboid with parameters specified by the user.

Provide pseudocodes
both both examples

2. Generate C code that will output the following


Construct a flowchart
for both examples
Flowchart
1. Flowchart show the flow of the codes or flows of actions which is
followed by the program
Start
2. Pseudo code in block form

Enter length,
width & height

Volume = length x
height x width

Print volume

Stop
Flowchart

Start

Enter length,
width & height

Volume = length x
height x width

Print volume

Stop
Pseudo code for Conditional
Statement

Generate the C code expression for the psedo code above

Write a full program for that


receive student grade from keyboard
input and print statement passed.
Converting Pseudo code to flow
chart for Conditional Statement
Generate the pseudo code to express passes given a grading marks

Generate the flow chart for the psedo code above


box - action block

diamond -
decision
block
Generate the C code expression for the flow chart above
Converting Pseudo code to flow
chart for Conditional Statement

Generate the the flow chart above

Modify previous program to complete


the if…else statement
Conditional Statement with Two
Conditions
Start

Enter grade

Modify previous program (passed of No / false


failed) according to UPM standard. grade >= 50

Yes / True Print Failed


if (grade >= 50) Print Passed
{
printf(“Passed”);
}
else Stop
{
printf(”Failed”);
}
Conditional Statement with
Three Conditions
If student’s grade is: Start
equal or greater than 55
print “C+ and above” Enter grade
between 50 and 54.99 print “C”
less than 50 print Failed Yes
grade >= 55
if (grade >= 55)
No Print C+
{
and above
printf(“C+ and above”); Yes
} grade >= 50
else if (grade >= 50)
{ Print C No
printf(“C”);
} Print Failed
else
{
printf(”Failed”);
} Stop
If…else Three Conditions:
Alternative Flow Chart
‘No’ at ‘Yes’ at
the main the main Start
trunk trunk
Enter grade

No
grade <= 55

Yes Print C+
and above
No
grade <= 50

Print C Yes

Print Failed

How does the code changes? Stop


Nested if…else
statement

Adapt this pseudocode for UPM subject grading


system

Generate the the flow chart for the nested loop


Code similarity if…else statement
Method 1 Method 2

Modify the the code for the nested loop


according to UPM grading system
Quiz
Generate or construct pseudocode, flowchart and codes for the
output below. Use if…else to decide which value is the smallest
and largest
Conditional if…else in Arduino

You might also like