Knowledge Unit of Science and Technology: Laboratory Manual (CC1021L) : (Programming Fundamentals) (Semester Fall-2021)
Knowledge Unit of Science and Technology: Laboratory Manual (CC1021L) : (Programming Fundamentals) (Semester Fall-2021)
Introduction to Array
Arrays in C++
An array in C++ is a collection of items stored at contiguous memory locations and elements can
be accessed randomly using indices of an array. They are used to store similar type of elements
as in the data type must be the same for all elements.
int arr[9]={40,55,63,17,22,68,89,97,89};
int arr1[10];
int n = 10;
int arr2[n];
Example:
#include <iostream>
[CC1021]: [Programming Fundamentals] Page 3
University of Management and Technology
using namespace std;
int main()
{
int numbers[5];
cout << "Enter 5 numbers: ";
}
//Printing Array Elements
for (int i = 0; i < 5; ++i)
{
Cout<< numbers[i];
}
return 0;
}
Lab Task:
1. Write a program in C++ to Take 10 integer inputs from user and store them
in an array and print them on screen.
[CC1021]: [Programming Fundamentals] Page 4
University of Management and Technology
2. Write a program in C++ to Take 10 integer inputs from user and store them
in an array. Now, copy all the elements in another array but in reverse order.
3. Write a program in C++ to Take 10 integer inputs from user and store them
in an array. Again ask user to give a number. Now, tell user whether that
number is present in array or not.
4. Write a program to find the sum of all elements of an array.
5. Write a program to find the product of all elements of an array.
6. Write a C++ program to take 20 integer inputs from user and print the
following:
number of odd numbers
number of even numbers
number of 0.