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

Lab 11 (arrays)

This document outlines a lab focused on the basics of arrays in computing, detailing various tasks for hands-on experience. It includes tasks for creating arrays, taking user input, performing operations like summation and difference calculations, and applying conditions for odd and even index assignments. The lab aims to enhance understanding of array traversal and manipulation through practical exercises.

Uploaded by

muhammadaliasjad
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Lab 11 (arrays)

This document outlines a lab focused on the basics of arrays in computing, detailing various tasks for hands-on experience. It includes tasks for creating arrays, taking user input, performing operations like summation and difference calculations, and applying conditions for odd and even index assignments. The lab aims to enhance understanding of array traversal and manipulation through practical exercises.

Uploaded by

muhammadaliasjad
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Introduction to Computing

Lab 11
Topic Basics of array
Learning objectives of this lab are to get hands on experience on the
Objective
concepts of array. It is on traversing array.

Task 1 – taking input

1 create an array arr1 of size ten; assign zero to all its positions in one go, and show
array elements one by one on screen with space.
2 create an array arr2 of size ten; assign zero to all its positions one by one through
value assignment, and show array elements one by one on screen with space.
3 create an array arr3 of size ten; assign zero to all its positions one by one through
loop, and show array elements one by one on screen with space.
4 create an array arr4 of size ten; assign 0 to 9 to array elements through loop, and
show array elements one by one on screen with space.
5 create an array arr5 of size ten; assign zero to all its positions through input from
user using loop [place a check that when user enters zero then assign that value to
the array element], and show array elements one by one on screen with space.

Task 2 – index work


1 create an array brr1 of size ten; get input from user, show only odd index values in
one go and then only even index values in one go.
2 create an array brr2 of size ten; get input from user, show only odd values in one go
and then even values in one go.
3 create an array brr3 of size ten; get input from user as odd index has odd value
[place a check that when user enters odd value then assign that value to the array
element] and even indexes can have any value, show array element by element.
4 create an array brr4 of size ten; get input from user as odd index has even value and
even index has odd value [place a check that when user enters you first check and
then assign that value to the array element], show array element by element.
5 create an array brr5 of size ten; get input from user as odd index has even value and
even index has odd value, show sum of the array and also calculate the average of
the array elements, [place a check that when user enters you first check and then
assign that value to the array element], show array element by element.
Task 3 – sum, difference and other operations

1 create an array XX of size ten; get input from user as odd index has even value and even
index has odd value, show odd index sum and even index sum [place a check that when
user enters you first check and then assign that value to the array element] , show array
element by element.
2 create an array YY of size twelve; get 10 inputs from user, calculate the odd index sum and
even index sum [place a check that when user enters you first check and then assign that
value to the array element]. You are not allowed to use any sum variable, use 11th element
for odd index element sum and 12th element for even index element sum of the array, then
show all array elements.
Please enter 10 numbers
12 54 25 62 -10 95 23 45 11 9
Elements in the array are
12 54 25 62 -10 95 23 45 11 9 265 61

3 create an array sum of size twelve; get input from user, calculate the difference between
every two neighbors [first and second element, second – first] of the array and show it on
the screen with appropriate message.
Please enter 12 numbers
12 54 25 62 -10 95 23 45 11 9 16 34
Difference between element 1 and 2 is 42
Difference between element 3 and 4 is 37
Difference between element 5 and 6 is 105
Difference between element 7 and 8 is 22
Difference between element 9 and 10 is -2
Difference between element 11 and 12 is 18
4 create an array a1 of size twelve; get input from user.
Create another array a2 of size 6. Calculate the difference between every two neighbors
[first and second element, second – first] of first array and store that difference in array two
one by one. At the end, show array two with appropriate message.
Please enter 12 numbers
12 54 25 62 -10 95 23 45 11 9 16 34
The difference between every two elements of array one is
Pair 1: 42
Pair 2: 37
Pair 2: 105
Pair 2: 22
Pair 2: -2
Pair 2: 18
5 Create an array of size twelve; get input from user, calculate the sum of every two neighbors
[first and second element] of the array and show it on the screen with appropriate message.
Find the largest sum of neighbors in this array. Find the largest sum of the neighbors in this
array. Show both on the screen with appropriate message.
Please enter 12 numbers
12 54 25 62 -10 95 23 45 11 9 16 34
Sum for element 1 and 2 is 66
Sum for element 3 and 4 is 87
Sum for element 5 and 6 is 85
Sum for element 7 and 8 is 68
Sum for element 9 and 10 is 20
Sum for element 11 and 12 is 50
6 create an array of size twelve; get input from user. Create another array of size 6. Calculate
the sum of every two neighbors [first and second element] of array one and store that sum
in array two one by one. Show array two with appropriate message. Find the smallest and
the largest value in array two and show on the screen with the message.
Please enter 12 numbers
12 54 25 62 -10 95 23 45 11 9 16 34
Min sum of neighbors in array is 20 of element 9 and 10 Max sum of neighbors in
array is 87 of element 3 and 4.
Task 4 – odd even index operation and value assignment

1 Create an array with size 10, take input from the user, and apply conditions that will follow
the following rule
o User enters the odd value, value should be place in odd index [odd index in array
starts form index 1] and the next odd value will be placed in the next odd index until
there is some empty odd index available.
o User enters the odd value, value should be place in odd index [even index in array
starts form index 0] and the next even value will be placed in the next even index
until there is some empty even index available.
o (Note: if one value you placed in index next user value cannot place in that index,
there may be odd or even values entered by user but array has no more space for
either odd index or even index.) Show appropriate message for either odd index not
available or even index not available till all spaces are filled.

2 create an array with size 10, take input from the user, and create another array of the same
size. Copy all the even values from array one to second array at first, when there is no even
value available in array then copy all odd values form array one to the second array. Show
array second on the screen, before that show the count of even values and odd values.
3 create an array with size 10, take input from the user [input can be 0 or 1, but no other
value is allowed]. Count the number of zeros and ones in the array, if number of ones are
greater than or equal to number of zeros first show all the ones then show all the zero
otherwise first show all the zeros and then show all the ones.

You might also like