0% found this document useful (0 votes)
29 views5 pages

Knowledge Unit of Science and Technology: Laboratory Manual (CC1021L) : (Programming Fundamentals) (Semester Fall-2021)

This document is a laboratory manual for an introduction to arrays class. It contains information about arrays in C++, including how to declare and initialize arrays, access array elements, and example programs. It provides tasks for students to write programs that take integer inputs from the user and store them in arrays, copy array elements in reverse order, check if a user number is in the array, calculate the sum and product of array elements, and count odd, even and zero elements in an array of size 20.

Uploaded by

Hassam Shahid
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)
29 views5 pages

Knowledge Unit of Science and Technology: Laboratory Manual (CC1021L) : (Programming Fundamentals) (Semester Fall-2021)

This document is a laboratory manual for an introduction to arrays class. It contains information about arrays in C++, including how to declare and initialize arrays, access array elements, and example programs. It provides tasks for students to write programs that take integer inputs from the user and store them in arrays, copy array elements in reverse order, check if a user number is in the array, calculate the sum and product of array elements, and count odd, even and zero elements in an array of size 20.

Uploaded by

Hassam Shahid
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/ 5

University of Management and Technology

Knowledge Unit of Science and


Technology
Laboratory Manual

[CC1021L]: [Programming Fundamentals]


[Semester Fall-2021]
Class: [BSSE]
Lab [7]: [Introduction to Array]

Instructor: [Ms. Hifza Munir]

[CC1021]: [Programming Fundamentals] Page 1


University of Management and Technology

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};

 Array declaration by specifying size

// Array declaration by specifying size

int arr1[10];

// declare an array of user specified size

int n = 10;
int arr2[n];

[CC1021]: [Programming Fundamentals] Page 2


University of Management and Technology
 Array declaration by initializing elements

// Array declaration by initializing elements

int arr[] = { 10, 20, 30, 40 }

// Compiler creates an array of size 4.


// above is same as  "int arr[4] = {10, 20, 30, 40}"

 Accessing Array Elements:


Array elements are accessed by using an integer index. Array index starts with 0 and goes
till size of array minus 1.

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: ";

//input array elements


for (int i = 0; i < 5; ++i)
{
cin >> numbers[i];

}
//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.

[CC1021]: [Programming Fundamentals] Page 5

You might also like