Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Cplab 4 Up

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

s CSL-113: Computer Programming Lab

Lab04: Loops in C++ (For, While & Do-While)

Objective(s):
1. To be able to apply Loops in C++
2. To be able to apply While Loop in C++
3. To be able to apply For Loop in C++
4. To be able to apply Do-While Loop in C++
5. To be able to apply Pretest and Post-test loop
6. To be able to apply Event and Counter Controlled Loop

Exercises

Exercise 1

Write a program to find the sum of first n Natural Numbers Positive integers such as 1, 2, 3……
n are known as natural numbers using for loop.

Exercise 2

Write a program in C++ that takes input from user repeatedly and calculates sum of those inputs
(only positive numbers) until a negative number is entered then displays the total sum calculated.
Write the program using While Loop.

Exercise 3

Write a program in C++ that takes input from user repeatedly and calculates sum of those inputs
(only positive numbers) until a negative number is entered then displays the total sum calculated.
Write the program using do-While Loop.

Exercise 4

Write a program to print tree structure by using loop by choice.


x
xx
xxx
xxxx

1/2
s CSL-113: Computer Programming Lab

xxxxx
xx
xx
xx
xx

Exercise 5

Write a C++ Program to display the pattern like pyramid using *.


Output:

Exercise 6

Write a program that receives start value and end value then displays series of numbers from
start to end value inclusive. Use do while to make sure user input smallest value first.

2/2

You might also like