0% found this document useful (0 votes)
16 views3 pages

Lab 4 06032024 102907pm

The document describes a lab exercise on while loops. It provides an example of a basic while loop that prints "Hello" 5 times. It explains that a while loop repeatedly executes a statement or block of statements as long as a given condition is true. The lab tasks require writing programs to print letters from Z-A, calculate factorials, print numbers in descending order, calculate series sums, find averages, convert numbers to binary, and display patterns - all using while loops. Students must submit 7 cpp files with the solutions.

Uploaded by

ironman9879357
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views3 pages

Lab 4 06032024 102907pm

The document describes a lab exercise on while loops. It provides an example of a basic while loop that prints "Hello" 5 times. It explains that a while loop repeatedly executes a statement or block of statements as long as a given condition is true. The lab tasks require writing programs to print letters from Z-A, calculate factorials, print numbers in descending order, calculate series sums, find averages, convert numbers to binary, and display patterns - all using while loops. Students must submit 7 cpp files with the solutions.

Uploaded by

ironman9879357
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

LAB NO.

4
LOOP STATMENTS II-WHILE LOOP

OBJECTIVE

▪ While Loop

DESCRIPTION

The “while” Loop

It is used to execute a statement or a set of statements as long as the given condition remains
true. The syntax of while loop is:

while (condition)
Statement;

Example

#include <iostream.h>
main()
{
int n = 1;
while(n<=5)
{cout<< “Hello”<<endl;
n=n+1;
}
cout<< “Program Ends”;}

Analysis

A while loop is a control flow statement that allows code to be executed repeatedly based on a
given boolean condition. The while loop can be thought of as a repeating if statement.

Understanding of basic concept of while loop. The while construct allows for repetitive
execution of a list of commands, as long as the command controlling the while loop executes
successfully (exit status of zero).
LAB TASKS:

Task1

Write a program using while loop which displays alphabets from Z-A.

Task2

Write a program to calculate factorial of a number using while loop. The output of the program
should be like:

Task3

Write a program to print natural numbers 1 to 20 in descending order. The output of the program
should be like:

Task4

Write a program to find the sum of the following series.


1+1/2+1/3+…..1/45
The output of the program should be like:

Task5
Write a program to find the average of N numbers using while loop. The output of the program
should be like:

Task6

Write a program that converts a number into its equivalent binary number using while loop.

Task7

Write a program to display following output using “while” loop

Deliverables:
1. Task1.cpp
2. Task2.cpp
3. Task3.cpp
4. Task4.cpp
5. Task5.cpp
6. Task6.cpp
7. Task7.cpp

You might also like