Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
53 views

Programming Fundamentals Lab 07 (Nested Loops)

This programming lab manual discusses nested loops, providing examples of a nested for loop and while loop to calculate sums and display patterns. The objectives are to understand nested loops and complete tasks that involve writing programs using nested loops to calculate series, display triangle patterns of characters, print prime numbers within a range, and display multiplication tables for a given number.

Uploaded by

Ahmad Abduhu
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views

Programming Fundamentals Lab 07 (Nested Loops)

This programming lab manual discusses nested loops, providing examples of a nested for loop and while loop to calculate sums and display patterns. The objectives are to understand nested loops and complete tasks that involve writing programs using nested loops to calculate series, display triangle patterns of characters, print prime numbers within a range, and display multiplication tables for a given number.

Uploaded by

Ahmad Abduhu
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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