You are on page 1of 2

MAT09 – Fundamentals of Computing I

LABORATORY ASSIGNMENT
DUE: NOVEMBER 12, 2021 (6:00PM)

Give 3 C-programming examples of each of the following branch structure:


1. IF-ELSE
2. NESTED IF-ELSE
3. SWITCH (CASE-STATEMENTS)
The examples should include the problem, the hand-written/type-written flowchart, C-
programming code and C-output screen. Submit your document as LASTNAME_MAT09-
LAB.pdf

EXAMPLE: (NESTED IF-ELSE)

PROBLEM: Create a C program that will input 3 numbers and output the LARGEST among 3
numbers.

FLOWCHART:

Start

a, b, c

Yes Yes
a>b a>c
a

No No

No c
b>c

Yes

b End
CODE:
#include <stdio.h>

int main(){
int num1, num2, num3;

printf("Please enter 1st number: ");


scanf("%d", &num1);
printf("Please enter 2nd number: ");
scanf("%d", &num2);
printf("Please enter 3rd number: ");
scanf("%d", &num3);

if (num1>num2){
if (num1>num3)
printf("\nNUM1 is the largest among 3 numbers.");
else
printf("\nNUM3 is the largest among 3 numbers.");
}
else{
if (num2>num3)
printf("\nNUM2 is the largest among 3 numbers.");
else
printf("\nNUM3 is the largest among 3 numbers.");
}

return 0;
}

OUTPUT:

You might also like