If Switch If If Switch
If Switch If If Switch
NAME : TOTAL
STUDENT ID : MARKS
1. Fixes
2. Complete
3. Manipulates
Practical Skill 4. Builds
Assessment 5. Display
[CLO2] 6. Lab Participation
7. Efficiency
Total Practical Skill Assessment
A. Total Practical Skill Assessment (70%) = /35 *70
1. Theory
Report 2. Discussion
Assessment 3. Conclusion
Total Report Assessment
B. Total Report Assessment (30%) = /15*30
Total A+B (100%)
DATE SUBMIT : DATE RETURN :
1 LEARNING OUTCOMES (LO):
1. Understand selection statements.
2. Apply selection statements.
2 OBJECTIVE
1. To fixes, Complete and Manipulates the selection statement.
2. To builds flowchart of selection statement.
3. To display the output of selection statement.
3 THEORY
The C statements that are used for altering the normal flow of a program are called control statements.
Various control statements, such as selection and looping statements, are available in C.
Selection statements are used to execute a set of instructions, just once, when the specified condition is
satisfied.
The types of selection statements available in C are if and switch.
The if statement is used for checking conditions and transferring the control to the body of the if statement
based on the condition.
The selection statement, which allows you to choose from a number of choices, is the switch statement.
4 EQUIPMENT / TOOLS
Computer, C programming language ( Dev-cpp, codeblock, dll)
Define IF statement
Answer:
Write the syntax for IF-ELSE Statement Draw flowchart for IF-ELSE Statement
Answer: Answer:
Write the syntax for SWITCH Statement Draw flowchart for SWITCH Statement
Answer: Answer:
PART B: PRACTICAL WORK AT LABORATORY
Practical Assignments 1 (Fixes Program)
To calculate series and parallel circuits.
Series parallel
Find an errors and correct the programme to illustrate the working of IF-ELSE statements to calculate the
total resistance for series and parallel circuit. Get the output after fixes all errors
#include <stdio> Correction:
main()
{
int selection;
float series, parallel;
float R1=100,R2=300, R3=500;
printf("1: Series Circuit\n");
printf("2. Parallel Circuit \n");
printf("Please Select your choice \n ");
scanf("%d", $selection);
IF (selection==1)
{
series = R1+R2+R3;
printf(" Total resistance = %.2d Ohm\n",series);
}
else if (selection==2)
{
PARALLEL = 1/(1/R1 +1/R2+1/R3) ;
printf(" Total resistance = %.6f Ohm\n",parallel);
}
else
{
printf(" wrong choice \n ");
}
return 0;
}
Output:
If selection =2
Practical Assignments 2 (Complete Program)
RT = R1 + R2 + R3
Series parallel
Complete all statements in the programme below to illustrate the working of SWITCH statements to
calculate the total resistance for series and parallel circuit. Get the output after fixes all errors
#include <stdio.h>
main()
{
Int____________________________________;
float series, parallel,R1,R2,R3;
printf("******************************************");
printf("\nEnter the value of R1= ");
scanf( _______________________________);
printf("\nEnter the value of R2= ");
scanf("%f",&R2);
printf("\nEnter the value of R2= ");
scanf ( _______________________________);
printf("******************************************");
printf("\n1: Series Circuit");
printf("\n2. Parallel Circuit ");
printf("\nPlease Select your choice ");
printf("******************************************");
scanf("%d",&selection);
switch(selection)
{
case 1:
series = R1+R2+R3;
printf(" _______________________________________”, ______________);
break;
case 2:
parallel = 1/(1/R1 +1/R2+1/R3) ;
printf(" _______________________________________”, ______________);
break;
default:
printf(" wrong choice \n ");
}
return 0;
}
Output:
If choice =2 If choice =1
Series parallel
Ask input from user the value of C1,C2 and C3
Flowchart :
Program:
Output:
If choice =1 If choice =2
Practical Exercise 2: Manipulates Program 2:
By referring to the Practical Assignments 2, draw flowchart and write a C program using IF-ELSE
statement to make a choice for calculate :
Choice 1: Total resistance of the circuit,
Choice 2: Current, I
Output:
Case 1
Case 3
Discussion for practical work 2
Knowledge: IF, IF-ELSE, and SWITCH statements work
Understanding: Concepts and Relate theory to practice