You are on page 1of 11

Algorithm:

C Program
with Sir Beets
Identify the Brand
Type in your answer

Icebreaker
intel Toblerone

Lay’s Adobe
Start

Pseudocode to
X
Flowchart Conversion
ü Composition (Problem 1)
1. Input X Y
2. Input Y
3. S=X+Y
4. Ave = S / 2 S=X+Y
5. Display Ave
• Alternation (Problem 2)
Ave = S / 2
• Iteration (Repeating Statements)

Ave

Stop
1. Open text editor software / C program IDE (e.g. Dev C++)
General Steps
2. Write C program code
in Compiling 3. Save the file in .C format (not .CPP – this is for C++)
and Running C 4. Compile (Locate the compile button)
Programs 5. Run (Locate the run button, the user screen should be visible)
Start
Pseudocode to
Flowchart Conversion X
ü Composition (Problem 1)
ü Alternation (Problem 2)
1. Input X
2. If (X % 2 == 0) Is, false
2.1 Then display “Even” X%2==0
2.2 Else display “Odd” ?
• Iteration (Repeating Statements)
true

“Even” “Odd”

Stop
Start
Pseudocode to
Flowchart Conversion Y=1
ü Composition (Problem 1)
ü Alternation (Problem 2)
ü Iteration (Repeating Statements)
1. Y=1 Is, false
Y <= 6
2. While (Y <= 6)
?
2.1 Display Y
2.2 Y = Y + 1
true

Y=Y+1 Stop
You would need to have
#include <stdio.h>
void main(){
// code inside
}

In // code inside you place the solution


Programming Input uses scanf( FS, AoV );
– FS – Format Specifier
– AoV – Address of Variable (&)

Mathematical processes are the same + semicolon(;)


Display uses printf(FS, V);
– V – Variable
– No variables needed? Do not include comma(,)
Used during input and output functions.
A way to tell the compiler what type of data is in a variable during
taking input using scanf() or printing using printf()

Format FORMAT DESCRIPTION


SPECIFIER
Specifier %d Integer Format Specifier
%f Float Format Specifier

printf(“%f”,PI); PI = 3.14159 3.141590


printf(“%.2f”,PI); PI = 3.14159 3.14
printf(“%.3f”,PI); PI = 3.14159 3.142
The price of all bags is being sold at 10% off. Create a solution
to determine the discounted price.

Float Example 1. Input Price


2. Discount = Price * 0.1
3. DiscountedPrice = Price - Discount
Do all previous activities and make C programs
out of them. All activities are limited only to using:
ü if-else
ü while
Practice ü variables and operators
Advanced Reading:
Output 1

Output 2

Added Output 3 Use while loop in all


Practice
Output 4

Output 5

You might also like