0% found this document useful (0 votes)
23 views3 pages

Lab Week 8 - Arrays

Uploaded by

nourayousefnour
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)
23 views3 pages

Lab Week 8 - Arrays

Uploaded by

nourayousefnour
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

CT018-3-1-ICP Page 1 of 3

Lab – Week 8
Array – 1D & 2D

1. How To Declare An Array (1D) – datatype arrayName[size];


2. How To Declare An Array (2D) – datatype arrayName[row][column];
3. How To Store/Retrieve/Update Array (1D) – for loop
4. How To Store/Retrieve/Update Array (1D) – nested for loop

Below is an example of Array (2D) with 3 rows and 4 columns:

Question 1: Array (1D) – Sum Of Elements


Write a program that initializes an array of the first ten (10) integers. The program should
calculate and print the sum of all its elements.

Hint:
 How to initialize array 1D with values – arrayName[3] = {1, 2, 3}
 To keep track of the sum of elements - _________ = _________ +-*/ _________

Asia Pacific Institute of Information Technology


CT018-3-1-ICP Page 2 of 3

Question 2: Array (1D) – Product Of Elements


Write a C program that will read a series of number from the user and store them in an array
called number[]. The program should then calculate and display the product of all integers
entered by the user.

Hint:
 Your program will crash if you create an array without the array size, e.g. number[].
Array is non-resizable so only create the array after asking the user a value and use
the input of the value as the size of the array
 To keep track of the product of elements - _________ = _________ +-*/ _________

Asia Pacific Institute of Information Technology


CT018-3-1-ICP Page 3 of 3

Question 3: Array (2D) – Sum Of Diagonal Elements


Initialize a 4x4 matrix (2D array) with the first sixteen (16) integers. Calculate and print the
sum of its main diagonal (from the top-left to the bottom-right).

Hint:
 How to initialize array 2D with values – arrayName[3][3] = {{1, 2, 3}, {4, 5, 6}, {7,
8, 9}}

Asia Pacific Institute of Information Technology

You might also like