0% found this document useful (0 votes)
26 views

Lab 7 Loops Practice

This document provides instructions for 6 tasks to complete a computing lab. The tasks involve using loops like for and while loops to solve problems like calculating powers, counting digits, finding greatest common divisors, counting positive and negative numbers, generating the Fibonacci sequence, and checking for palindromic numbers.

Uploaded by

Muhammad Umair
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

Lab 7 Loops Practice

This document provides instructions for 6 tasks to complete a computing lab. The tasks involve using loops like for and while loops to solve problems like calculating powers, counting digits, finding greatest common divisors, counting positive and negative numbers, generating the Fibonacci sequence, and checking for palindromic numbers.

Uploaded by

Muhammad Umair
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Introduction to Computing

LAB # 7
Instructor Name: Faiza Khadim

Instructions:
 You have to submit CPP files of the program in a folder, named your Registration Number.
 You have to upload your lab tasks on CMS.
 All program codes should be written in C/C++. Students should use Visual studio compiler
for coding.
 Indent and comment your code.
 Use meaningful variable names
 Plan your code carefully on a piece of paper before you implement it.
Learning Objectives:
 Demonstrate knowledge of basic concepts of Loops (for and while) in programming C++
 Recall previously learned basic concepts
 Understanding problem statements and designing an appropriate solution
 Solve different problems using selection statements.

Task 1: (Using while Loop)

Write a C++ program that takes two positive integers a and b as input from the user and displays the
value of ab. (Note: Do not use any built-in function for this purpose). a and b can be negative.
Expected Output
Enter the value of a: 2
Enter the value of b: 3
Power = 23= 8

Enter the value of a: -2


Enter the value of b: -3
-2 to the power of -3 is -0.125
Task 2: (Using while loop)

Write a C++ program that takes a positive integer as input from the user and counts the number of
digits in that integer.
Expected Output
Enter a digits=45856
Digits in 45856= 5

Task 3: (Using for Loop)


Write a C++ program that takes two positive integers as input and displays their Greatest Common
Divisor (GCD).
Expected Output
Input the first number: 25
Input the second number: 15
The Greatest Common Divisor is: 5

Task 4: (using while Loop)


Write a C++ program that take inputs from user until user enter 0 and count the number of positive
and negative number at the end.
Expected Output
Enter Input: 7
Enter Input: -20
Enter Input: 58
Enter Input: 96
Enter Input: 0
Count of Positive Number=3
Count of Negative Number=1

Task 5: (Using While Loop)


The Fibonacci series is a sequence of numbers in which each number is the sum of the two preceding
ones, usually starting with 0 and 1. The first few terms of the Fibonacci series are:
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, ...
Write a C++ program to print the series till term.
Expected Output
Enter the number of terms: 10
Fibonacci Series: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34
Task 6: (Using for loop)
Write a C++ program that takes input form user and tell the number is palindrome or not.
Expected Output
Enter a positive number: 12321
The reverse of the number is: 12321
The number is a palindrome.

Enter a positive number: 12331


The reverse of the number is: 13321
The number is not a palindrome.

End of LAB 7 😊

You might also like