National University of Computer and Emerging Sciences
Lab Manual
for
Programming Fundamentals
Course Instructor Mr. Waqas Manzoor
Lab Instructor(s) Mr. Muhammad Waqas
Mr. Raja Muzammil Muneer
Section BDS-1B1, 1B2
Semester Fall 2021
Department of Computer Science
FAST-NU, Lahore, Pakistan
Page 1 of 3
Objectives
After performing this lab, students will be able to:
Write C++ Code for the problems involving For loop (Without nesting).
Break Statement
Instructions
For each problem, your filename should be “q Number”.cpp. e.g For Problem 1, create
“[Link]”.
Zip all files in a folder and your submission zip filename must be your rollno. e.g
“[Link]”. Note your zip file shall contain all the .cpp files for the problems you solved.
Submit the zip folder on Google classroom.
Plagiarism is strictly prohibited.
Good Luck.
Problems
Write C++ Code of the following Problems using For Loop.
Problem#1
Write a program that prompts the user to enter a number and prints odd number from 1 to that
number and also display their sum.
Input Output
10 1,3,5,7,9
Sum:23
Problem#2
Write a program to multiply two non-negative numbers without using multiplication operator
using For loop.
Problem#3
Write a program that prompts the user to enter a number n and prints average of n squared
natural number.
Input Output
5 1,4,9,16,25
Avg=11
Page 2 of 3
Problem#4
Write a program that takes an input and returns the answer for following equation.
(1 + 2 + ... + n)2 – (12+ 22 + ... + n2)
For Example
Enter a number: 5
(1 + 2 + ... + 5)2 – (12+ 22 + ... + 52) =225-55=170
Input Output
6 441-36=405
Problem#5
Write a program that prompts the user to enter a number and print its factors.
Input Output
Input a Number: 16 Factors: 1,2,4,8,16
Page 3 of 3