You are on page 1of 3

National University of Computer and Emerging Sciences

Laboratory Manual
for

Introduction to Computing
(CS 101)

Course Instructor

Mr. Muhbasher Baig

Lab Instructor(s)

Zara Asif
Asma Hanif

Sections

Department of Computer Science


FAST-NU, Lahore, Pakistan

Lab Manual 04
While/nested while loops
Objectives
Objectives of this lab are:
Write simple programs using while/nested while loops

Important Notes

Use meaningful variable names

FAST-NU, Lahore

Introduction to Computing (CS 101) Lab Manual

Indent your program so that statements inside a block can be distinguished from another block

Problems / Assignments
Problem 1: Write a program that inputs a number from Estimated completion time (mins):20
the user and outputs the table of first 10 multiples for that
number
A sample input and output is given below:
3
3x1=3
3x2=6
3x3=9
3 x 4 = 12
3 x 5 = 15
3 x 6 = 18
3 x 7 = 21
3 x 8 = 24
3 x 9 = 27
3 x 10 = 30
Problem 2: Output the digits that make up a number

(input)
(your programs output)

Estimated completion time (mins):30

Input a number from the user and output its digits, one digit per line. For example, if the user inputs
7854, then your program should output:
The digits of 7854 are:
7
8
5
4

Problem 3:Input numbers from the user until a negative Estimated completion time (mins):40
number is entered and output the average of the all the
numbers entered
A sample input and output is given below:
Enter numbers:
5
7
8
9
Copyright 2016. FAST-NU, Lahore

(input)
(your programs output)

Page 2

FAST-NU, Lahore

Introduction to Computing (CS 101) Lab Manual

10
-5
The average of the numbers is 5.666667
Problem 4: Output a diamond shape
Estimated completion time (mins):40
Input the total number of lines of the diamond shape from the user and output the diamond shape. For
example if the user inputs 5, then your program should print:
*
***
*****
***
*

References
C++ how to program by Deitel and Deitel
cplusplus.com
https://msdn.microsoft.com/en-us/library/jj620919.aspx

Copyright 2016. FAST-NU, Lahore

Page 3

You might also like