Nested For Loop-Introduction to Programming-Lab Mannual, Exercises of Computer Programming

This is lab manual in form of lecture slides for Introduction to Programming course. It was delivered by Prof. Abhimoda Arora at Alagappa University. It includes: Nested, FOR, Loop, Specified, Task, Output, Construct, program, pattern, Input, Pyramid, Rows, Repetition, Structure

Typology: Exercises

2011/2012

Uploaded on 07/31/2012

dhairya
dhairya ๐Ÿ‡ฎ๐Ÿ‡ณ

5

(4)

32 documents

1 / 13

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Nested For Loop
๎€ŠSeveral loops can be used for a specified Task
๎€Šfor(int j = 0 ; j < 5 ; j++)
for(int k = 0 ; k < 4 ; k++)
Use Nested for Loops to Show this on the
output Screen
1. 1 2 3 4 5 6 7 8 9
2. 1 2 3 4 5 6 7 8 9
3. 1 2 3 4 5 6 7 8 9
4. 1 2 3 4 5 6 7 8 9
docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd

Partial preview of the text

Download Nested For Loop-Introduction to Programming-Lab Mannual and more Exercises Computer Programming in PDF only on Docsity!

Nested For Loop

๎€Š

Several loops can be used for a specified Task

๎€Š

for(int j = 0 ; j < 5 ; j++)

for(int k = 0 ; k < 4 ; k++)

Use Nested for Loops to Show this on the

output Screen

Lab Task

๎€Š Use for loops to construct a program that displays the following

two patterns. The number of rows for both patterns will be same

and will be taken as an input from the user. Pattern b should be

shown bellow pattern a

Pattern (a) Pattern (b)









while

Repetition Structure

Example

int product = 2; while ( product <= 1000 ) product = 2 * product; product <= 1000 (^) product = 2 * product true false

For vs While

๎€Š

The for loop does something a fixed number of

times. What happens if you donโ€™t know how

many times you want to do something before

you start the loop?

// while4.cpp // prints numbers raised to fourth power #include #include //for setw using namespace std; int main() { int pow=1;//power initially 1 int numb=1;//numb goes from 1 to ??? while( pow<9999 )//loop while power <= 4 digits { cout << setw(2) << numb;//display number cout << setw(5) << pow << endl;//display fourth power numb = numb + 1;//get ready for next power pow = numbnumbnumb*numb;//calculate fourth power } cout << endl; return 0; docsity.com

Lab Task

Write a program to find the sum of the following

series:

Lab Task

๎€Š

Write a Program to calculate the number of

digits in a user entered number.

Lab Task

๎€Š

Write a Program to make a square whose

boundaries are made of * and is empty from

inside, its length and width will be entered by

user