Lab 1
Lab 1
Section O6
Lab Objective:
The basic purpose of this laboratory is revision of some preliminary concepts of c++ that has been
covered in the course of Introduction to Computing and Programming Fundamentals. Its objective is
to:
Instructions:
Sample solution:
#include <iostream>
using namespace std;
int find_factorial(int num)
{
int fact = 1;
while (num > 1)
{
fact = fact*num;
num--;
}
return fact;
}
int main()
{
int num;
cout << "Enter a number to find factorial: ";
cin >> num;
if (num >= 0)
{
cout << "Factorial of " << num << " is: " << find_factorial(num) <<
endl;
}
else
{
cout << "Please enter a positive number!\n";
}
}
Lab Tasks:
Task 1:
Write a function that asks the user to enter a number N by showing the message “How many
numbers you want to enter”. After that the user will input N integer numbers one by one. From
those input numbers, place only the EVEN numbers in an array. Ask the User if he wants to enter
more numbers, if user says yes, repeat the above process until the user is interested to enter more
numbers. In the end it will tell how many time it press y (hint: static variable)
Task 2:
Write a program to sort the given ARRAY [98.7, 65.8, 11.9, 9.5, 67.9, 90.5, 90.9, 15.8, 16.9,
98.7] in ascending order using selection sort, print the output after each iteration till final
output. Also, print the repeated element.
Task 3:
Write a function that prints the multiples of nth number in an integer array
Input:
1,4,10,15,12,24,25,6,8,70
n=5
Output:
10,15,25,70
Task 4:
Write a function Array_Max_Index which takes an array of integers and its size as
parameters and returns the index of the largest integer in the array.
Task 5:
Write a function Array_Copy which takes two char arrays as input and copies all the
elements of the first array into the second.
Task 6: