PF Lab 6
PF Lab 6
Lab Objective:
To practice for loops and switch cases and to get better understanding of
how to use them.
Lab Description:
Syntax:
Output:
Nested Loops:
A loop that is inside another loop is called a nested loop. A clock is a good example of something
that works like a nested loop. The second hand, minute hand, and hour hand all spin around the face
of the clock. Each time the hour hand increments, the minute hand increments 60 times. Each time
the minute hand increments, the second hand increments 60 times. Here is a program segment with
a for loop that partially simulates a digital clock. It displays the seconds from 0 to 59:
Example
Output:
Switch case
Lab Tasks:
• Task1: C++ program to Print Table of any Number.
The concept of generating table of any number is multiply particular number from 1 to 10.
num * 1
num * 2
num * 3
num * 4
num * 5
num * 6
num * 7
num * 8
num * 9
num * 10
• Task2: Find power of any number using for loop.
• Task7: Write a C++ program that will print the following pattern.
*
**
***
****
*****
******
*******
• Write a C program print total number of days in a month using switch case.
• Write a C program to check whether an alphabet is vowel or consonant using
switch case.
Think??
• What will be the output of the C program?
#include<stdio.h>
int main()
{
for(5;2;2)
{
cout<<"Hello";
}
return 0;
}
• What will be the output of the C program, if input is 6?
#include<stdio.h>
int main()
{
int i;
for(i = 0; i>9; i+=3)
{
cout<<"for ";
}
return 0;
}
#include<stdio.h>
int main()
{
for(;;)
{
cout<<”10”;
}
return 0;
}