Figure 1. Conditional Activity 1 Flowchart
Figure 1. Conditional Activity 1 Flowchart
Activity Section
Conditional Activity 1a
a. Problem
Write a C program that will determine whether the inputted
age is qualified to vote or not qualified to vote.
b. Algorithm
Input: Enter age (age)
Process: Classify age (age) to whether voting is permitted or not
Output: Display classification of age (Too young or qualified to
vote)
c. Flowchart
d. Source Code
e. Program Output
Conditional Activity 1b
a. Problem
Write a C program that will determine whether the inputted age is
qualified to vote or not qualified to vote.
b. Algorithm
-Input: Enter age (age)
-Process: Classify age (age) to see if user is qualified to vote or not
-Output: Display classification of age
c. Flowchart
Figure 2. Conditional Activity 2 Flowchart
The figure above shows the process of determining whether the
inputted age is qualified to vote or not. The program starts with asking
for a number. If the number is greater than equal to 1 but less than
equal to 100, then the program proceeds; otherwise, the program
displays the statement “Out of Range!” The program then determines
whether the inputted age is above 18 wherein the statement “Qualified
to vote” is then displayed; otherwise, the statement “Out of Range!” is
presented. The program then comes to a stop afterwards.
d. Source Code
e. Program Output
Conditional Activity 2
a. Problem
Write a C program that determines whether the inputted value is
the same as the magic number, 143 wherein the output words are
“I love you!”; otherwise, the output is “Sorry, better luck next
time”.
b. Algorithm
-Input: Enter number (mn)
-Process: Determine if number is 143
-Output: Display results
c. Flowchart
The figure above indicates the process the program must execute. The
goal of the program is to determine whether the inputted number is equal to
the magic number. If the inputted value is equal to 143, the program presents
the statement “I love you!”. If the inputted value is not 143, the program
shows “Sorry, better luck next time”. Since this is the only scope of the code,
the program is terminated afterwards.
d. Source Code
e. Program Output
Conditional Activity 3
a. Problem
Write a C program that determines whether a value is positive or
negative.
b. Algorithm
-Input: Enter a number (n)
-Process: Determine whether number is positive or not
-Output: Display positive if n is =/ 0 or else display negative
c. Flowchart
e. Program Output
Conditional Activity 4
a. Problem
Make a C program that will determine whether the inputted value is
odd or even.
b. Algorithm
Input: Enter a number (n)
Process: Compute and determine whether a number is even or odd
Output: Display odd if number is odd or even if number is even
c. Flowchart
e. Program Output
III. Supplementary Section
Conditional Supplementary 1
a. Supplementary Worded Problem
Write a C program that will determine the BMI classification given
the weight and height.
b. Supplementary Program Algorithm
-Input: Enter name, height, and weight (a, h, w)
-Process: Compute for BMI (b) and classify BMI (b)
-Output: Display weight(w), height(h), BMI(b), and BMI
classification
c. Supplementary Program Flowchart
Figure 6. Conditional Supplementary 1 Flowchart
The figure above shows the procedure followed by the program
to execute the wanted output. The input for this program is the weight
and the height. The process of the code involved the computation of
the BMI index which then is used to determine whether the BMI index
falls under the underweight, healthy, overweight, and obese
categories. The program then presents which category the inputted
values are in, the BMI value, the weight, and the height. The program
stops after this step.
d. Supplementary Source Code
e. Supplementary Program Output
IV. Program Observation and Conclusion
Activity 1a makes use of the if-else statement to determine whether the value
is within the bounds of the perimeter set. In this lesson, the program prints
statements whether the conditions fall true or not. If the value and given condition
proves to be true, the program outputs a statement. If the value does not fall into
the category of the condition, another statement is issued. The else statement need
not be written a condition as this is expected to be what the condition of if statement
is not.
Activity 1b makes use of the if-else statement and yet again is exactly like
activity 1a. However, in this case, perimeters were set and two if statements were
created. The program is expected to determine whether the input is greater than
equal to 1 and less than equal to 100 for the first if-else statement. If this initial
statement is proven to be true, the program proceeds to the second if-else
statement. If both of these statements are proven to be false respectively, similar
statements will be printed.
Activity 2 also makes use of the if-else statement. In this case, it is used to
determine the similarity of the digits in the condition. If the program finds the
condition to be different to that in the if-else statement, the program will execute a
statement. If the program finds the condition to have been met, the program will
execute the statement listed in the if statement. This lesson exhibits the ability of
the if-else statement to follow through a non-arithmetic based condition.
Activity 3 aims to determine whether the inputted value is a positive or
negative number. The condition of the if statement in this case is determining
whether the inputted value is greater than 0. It is a known fact that all positive
integers are greater than zero. If this condition is proven to be false, the program
will directly proceed to the statement within the else statement. In this case, the
else statement will print out negative. This lesson is fairly simple; if-else statements
can be used to categorize inputted values.
Activity 4 is almost the same as activity 3 as seen in its code. In this case, the
program aims to determine whether the inputted value is odd or even. The
condition of the if statement in this lesson is to see whether the inputted value when
divided by 2 is equal to 0. All even numbers are divisible by 2, and so this is the main
principle utilized in the if-else statement. If the inputted value turns out to not be
divisible by 2, the program will immediately know that the value is an odd number.
Supplementary 1 makes use of the if-else statement and arithmetic. The
program is expected to calculate the BMI value given the height and the weight. The
program is then expected to determine which if statement this condition falls under.
The four categories are underweight, healthy, overweight, and obese. This activity
contains more if statements for there are more conditions in the wanted output.
Experiment 2 extensively uses the concepts of If-Else statements in addition
to the basic input output statements and arithmetic in C programming. As inferred
in the activities, the condition of the if statement, when proven false, immediately
goes to another if statement to see if it satisfies the condition of this if statement. If
all if statements are not satisfied, the program will run the else statement. It can also
be noted that if-else statements are best used when arithmetic is utilized. Several if-
then statements may also exist within a single program; there is no limit in the usage
of if-then statements.