Professional Documents
Culture Documents
05 Loops
05 Loops
Namayala Phesto
Revision
Complete a program for a simple calculator using both if else and
switch case statements.
Highlights the limitations of switch case statement.
Accept views, challenges encountered or some other businesses from
students.
Write a simple program to test if entered number is even or not
Write both flow chart and a simple program test if entered integer
number is ODD or not
Program to check if entered number is even
#include <stdio.h>
int main() {
int num;
printf("Please enter a number \n");
scanf("%d",&num);
if (num%2 == 0)
printf("%d is EVEN",num);
else
printf("%d is NOT EVEN",num);
return 0;
}
Program to check if entered number is odd
or not
#include <stdio.h>
int main() {
int num;
printf("Please enter a number \n");
scanf("%d",&num);
if (num%2 == 1)
printf("%d is ODD",num);
else
printf("%d is NOT ODD",num);
return 0;
}
other
Both flow chart and a program for a simple calculator was written in
the class and discussed
Objectives
Define what is looping statement
Differentiate loops from conditional statements
Identify categories of looping statements
Create a general flow chart
Create flow charts and examples for each type of looping
statement
What is looping statement ?
Looping statement are the statements execute one or more
statement repeatedly several number of times.
In programming language there are three types of loops;
While loop,
for loop and
do-while loop.
Why Loops
When you need to execute a block of code several number of times
then you need to use looping
Example
1. What a program which prints your name 100 times
2. Write a program which prints all numbers between 1 and 10000
inclusive