You are on page 1of 7

Programming Fundamentals

Lab
Lecture 08

Prepared by Aqsa Gul, Lecturer Institute of Management Sciences Peshawar


Nested For Loop

 Syntax
for ( init; condition; increment ) {
for ( init; condition; increment ) {
statement(s);
}
statement(s); // you can put more statements.
}

Prepared by Aqsa Gul, Lecturer Institute of Management Sciences Peshawar


Flow control

Prepared by Aqsa Gul, Lecturer Institute of Management Sciences Peshawar


Example

 Write a program to print Table using nested for loop

Prepared by Aqsa Gul, Lecturer Institute of Management Sciences Peshawar


int main()
{
int i;
int j;
for(i = 12; i <= 14; i++)
{ /*outer loop*/
cout << "Table of " << i << endl;
for(j = 1; j <= 10; j++)
{ /*inner loop*/
cout << i << "*" << j << "=" << (i*j) << endl;
}
}
return 0;
}

Prepared by Aqsa Gul, Lecturer Institute of Management Sciences Peshawar


Task

 Write a program in C++ to display the pattern like right angle triangle with number.

1
12
123
1234
12345

Prepared by Aqsa Gul, Lecturer Institute of Management Sciences Peshawar


Task

 Write a program in C++ to make such a pattern like a pyramid with an asterisk.

Prepared by Aqsa Gul, Lecturer Institute of Management Sciences Peshawar

You might also like