You are on page 1of 4

Introduction to Computing (ITC M6

& M13)
Lab 10

Arrays
Topic
Objective Making students familiarize with the concepts of how to write basic programs with
& proper syntax and semantics, Datatypes in C++, variable declaration and initialization,
Outcome basic input and output of variables and understand the flow of program, loops and
s arrays concepts.

Instructions:
 Indent your code.
 Comment your code.
 Use meaningful variable names.
 Plan your code carefully on a piece of paper before you implement it.
 Name of the program should be same as the task name. i.e. the first program should
be Task_1.cpp
 You are not allowed to use any built-in functions
 You are required to follow the naming conventions as follow:
 Variables: firstName; (no underscores allowed)
Task 1:
Write a program that initialize an array of size 10. Print values on screen.
Example:
Array [10]= 23 45 67 78 3 567 0 -1 4 67

Output:
values are
23 45 67 78 3 567 0 -1 4 67

Task 2:
Write a program that initialize an array of size 10. Print only odd values on screen.
Example:
Array [10]= 23 45 67 78 3 567 0 -1 4 67

Output:
Odd values are
23 45 67 3 567 -1 67

Task 3:
Write a program to:
a) Initialize an array of 7 entries for students’ roll numbers.
b) Output the last roll number
c) Set the value of 5th roll number to 40.
d) Set the value of 3rd roll number to the addition of first two roll numbers and
Subtract 2 out of it.
e) Print whole array

Example:
Student[7]= 1 4 2 6 7 8 9
Output:
Last Roll number is 9

1 4 5 6 40 8 9

Task 4:
Write a program that initialize an array of size 10. Print the whole array in reverse order.
Example:
Array [10]= 23 45 67 78 3 567 0 -1 4 67

Output:
67 4 -1 0 567 3 78 67 45 23
Task 5:
Write a program that initialize an array of size 10. Print all even numbers in array.
Example:
Array [10]= 23 45 67 78 3 567 0 -1 4 67

Output:
78 0 4
Task 6:
Write a program that initialize an array of size 10. Find the Sum and average of all numbers and print
the result on screen.
Example:
Array [10]= 23 45 67 78 3 567 0 -1 4 67

Output:
Sum of numbers is:853
Average of numbers is: 85.3

Task 7:
Write a program that initialize an array of size 10. Find the Sum and average of only even numbers and
print the result on screen.
Example:
Array [10]= 23 45 67 78 3 567 0 -1 4 67

Output:
Sum of numbers is:82
Average of numbers is: 27.3333

Note: Here even numbers are 3 hence average is 82/3

Task 8:
Take input of 10 size of array and ask user to enter numbers. Your program should add +1 in values at
even index and -1 in value at odd index.

Example:
Array [10]= 5 45 67 78 365 0 -1 4 71 3

Output:
6 44 68 77 366 -1 0 5 70 4

Task 9:
Take input of 10 size of array and ask user to enter numbers. Print all numbers in array that are multiple
of greater than 10 and less than 100.
Example:
Array [10]= 5 45 67 78 365 0 -1 4 71 3

Output: 45 67 78 71

You might also like