National University of Computer and Emerging Sciences: Lab Manual Programming Fundamentals
National University of Computer and Emerging Sciences: Lab Manual Programming Fundamentals
Lab Manual
for
Programming Fundamentals
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
“q1.cpp”.
Zip all files in a folder and your submission zip filename must be your rollno. e.g
“21L1234.zip”. 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
Page 3 of 3