ComputingLab DroneTraining2
ComputingLab DroneTraining2
• Exercise:
Enter English, History and Economics subject marks of a
student from key board. Find out the average mark of
the student. Write a program to evaluate the results for
a student applying the rule: pass marks (30+), 2nd class
(40+), 1st class(60+)
/* Program to check whether a no. is even */
Flowchart # include<stdio.h>
void main()
False
Condition {
int num;
True
STOP {
printf(“\n Number is even”);
}
}
if – else statement
• If specific statements are to be executed in both
cases (either condition is true or false) then if –
else statement is used.
• Syntax: if (condition)
{
statement 1;
False
statement 2; Test
Condition
}
else True
• if (condition1)
statement1; false
condition 1
else if(condition2) false
condition 2
statement2; true
false
else if(condition3) Statement 1 true condition 3
default statement;
Default statement
Next statement
Switch statement
• Switch is a multi-way decision making statement which
selects one of the several alternatives based on the
value of single variable or expression.
• It is mainly used to replace multiple if-else-if statement.
• Syntax:
switch (expression)
{ case constant1 :
statement(s);
break;
case constant2 :
statement(s);
break;
… …. …
default: statement(s);
}