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

Programming Fundamentals

Lab Manual (Lab 7)

Topic: Nested loops

Lab Instructors:
Ahmad Abduhu

Session: Fall 2018

School of Systems and Technology


UMT Lahore Pakistan
Objectives
The objective of the lab is to understand the concept and how to implement Nested for loop, nested while
loop. At the end of this lab students will be able to use all type of loops.

Sample Task 1: Nested for loop

#include<iostream>

using namespace std;

int main(){

inti,j,k;

for(i=0;i<3;i++){

for(j=0;j<3;j++){

cout<<i+j<<endl;

} }

return 0;

Sample Task 2: Nested while loop

#include<iostream>
using namespace std;

int main(){
int i = 0;
int j = 0;
while(i < 10){
cout<<"i:"<< i<<endl;
while(j < 10){
cout<<"j:"<< j<<endl;
j++;
}
i++;
}
}
Lab Tasks

Task 1:
Write a program that inputs the value of x and range. Its then calculates and prints the sum of the
following series:

1 + 1/x + 1/x^2+1/x^3....

Task 2:
Write a program that inputs the height of triangle and displays a triangle of characters. For
example, if the user enters 5 it displays the following:
Enter the height of the triangle:
A
BC
DEF
GHIJ
KLMNO
PQRS
TUV
WX
Y

Task 3:
Write a program to print the following triangle patterns on console
Task 4:
Write a program to print all prime numbers between the range taken from the user. (Ask the user to
enter starting and ending numbers).

Task 5:
Write a program to print the multiplication table of the number entered by the user. The table should
get displayed in the following form.

29 * 1 = 29
29 * 2 = 58
29 * 3 = 87
.
.
.
29 * 10 = 290

You might also like