ITC_Lab Week 11
ITC_Lab Week 11
Topics: Arrays
Instructions:
• Create separate C++ source files for each task, named as “task1.cpp”, “task2.cpp”, and so on
depending on the task number.
• After completing all tasks, place all .cpp files into a folder. Name the folder with your
university registration number (e.g., L1F20BSCS0999). Compress the folder into a .zip file
and upload it on the portal.
• Ensure that the work you submit is entirely your own. Avoid copying from peers, online
sources, or any other unauthorized material. Plagiarism will not be tolerated.
• If you encounter difficulties, feel free to reach out to the instructor. Collaboration and
discussion are encouraged, but the final implementation should be your own work.
• Write clean and well-structured code. Use comments to explain key sections of your code to
make it easier for others (and yourself) to understand.
• These tasks are designed to help you strengthen your logical thinking and problem-solving
skills. Think through each problem carefully before starting to code. The aim is to develop a
deep understanding of the problem and to devise solutions independently.
Array Traversal
You can use loops like for or while to iterate over the array.
Partial Initialization
Uninitialized elements are automatically set to 0.
Size of an Array
To get the size of an int array in C++, divide the total size of the array by the size of an int:
Task 1
Write a program to declare an integer array of size 5, initialize it with values {10, 20, 30, 40, 50},
and use a loop to print all the elements.
Task 2
Write a program to declare an integer array of size 5 with values {5, 10, 15, 20, 25}, calculate
the sum of its elements, and find their average.
Task 3
Write a program to declare an integer array of size 5 with values {3, 8, 1, 6, 2}. Find and print
the largest and smallest elements in the array.
Task 4
Write a program to declare an integer array of size 5 with values {1, 2, 3, 4, 5} and reverse its
elements.
• Expected Output: 5, 4, 3, 2, 1
Task 5
Write a program to declare an integer array of size 5 with values {1, 2, 3, 4, 5}. Count and print
how many even and odd numbers the array contains.
• Expected Output: The array contains 2 even numbers and 3 odd numbers.
Task 6
Write a program to declare an integer array of size 5 with values {10, 20, 30, 40, 50} and shift all
its elements to the left by one position. The first element should move to the end.
Task 7
Write a program to declare two integer arrays of size 5. Initialize the first array with values {1, 2,
3, 4, 5} and copy its elements into the second array.
• Expected Output: Original Array: 10, 20, 30, 40, 50, Copied Array: 10, 20, 30, 40, 50
Task 8
Write a program to declare an integer array of size 5 with values {7, 5, 9, 2, 8} and find the
second largest element.
Task 9
Write a program to declare an integer array of size 5 with values {3, 6, 9, 12, 15}. Check if a
specific number exists in the array.
Task 10
Write a program to declare two integer arrays of size 3 with values {1, 2, 3} and {4, 5, 6}. Merge
them into a third array and print the result.