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

Assignment 3 Arrays

This document discusses arrays in C programming. It includes questions about arrays that require filling in blanks, stating whether statements are true or false, writing C code to perform array operations, and writing full C programs to perform tasks using arrays. Some key points covered are: - Arrays allow storing multiple values of the same type - Array elements have the same data type and size - An index or subscript is used to refer to a specific element - Initializing, declaring, and naming an array reserves memory for it - Loops can be used to iterate through arrays and perform operations on elements

Uploaded by

Muhammad Hassan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
86 views

Assignment 3 Arrays

This document discusses arrays in C programming. It includes questions about arrays that require filling in blanks, stating whether statements are true or false, writing C code to perform array operations, and writing full C programs to perform tasks using arrays. Some key points covered are: - Arrays allow storing multiple values of the same type - Array elements have the same data type and size - An index or subscript is used to refer to a specific element - Initializing, declaring, and naming an array reserves memory for it - Loops can be used to iterate through arrays and perform operations on elements

Uploaded by

Muhammad Hassan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Assignment 3: Arrays

1 Fill in the blanks.

(i) Lists and tables of values are stored in _________________.


(ii) The elements of an array are related by the fact that they have the same
____________ and ______________.
(iii) The number used to refer to a particular element of an array is called its
____________.
(iv) The process of an placing the elements of an array in order is called _________.
(v) The process of determining if an array contains a certain key value is called
____________.
(vi) The names of first 3 elements of an array B are ______, _______, and _______.
(vii) Naming an array, stating its type, an specifying the number of elements in the
array is called ______________ the array.
(viii) __________ is a collection of homogeneous data elements.
(ix) If we did not assign any initial values to array elements then their values are
___________.
(x) Write down any two names of algorithms used for searching _________,
____________.

2 State whether the following are true or false. If the answer is false, explain why.
(i) an array can store many different types of values.
(ii) An array subscript can be of data type float.
(iii) If there are fewer initializers in an initializer list than the number of elements in
the array, C automatically initializes the remaining elements to the last value in
the list of initializers.
(iv) It is an error if an initializer list contains more initializer than there are elements in
the array.
(v) To refer to a particular location or element within an array, we specify the name of
the array and the value of the particular element.
(vi) An array declaration reserves space for the array.
(vii) To indicate that 20 locations should be reserved for integer array Y, the
programmer writes the declaration as
Y[20];
(viii) to refer to 15th element of an array D the programmer should write
D[15]
(ix) Array elements are scattered in the memory.
(x) Exchanging the values of two array elements is called swaping.

3 Write C statements to accomplish each of the following.


(i) Display the value of the seventh element of character array f.
(ii) Input a value into element 4 of floating-point array b.
(iii) Initialize each of the 5 elements of integer array g to 8.
(iv) Total the elements of floating-point array c of 100 elements.
(v) Swap 3rd and 4th elements of array c
4 Write down a program that enters 50 numbers through keyboard in an integer array. You
have to find out how many of them are positive, how many are negative, how many are
even and how many are odd.

5 Write down a C program that defines two arrays of integers X and Y of size 20 each.
Assign 20 random numbers in array X. Assign 20 entries of array X to array Y such that
X[0] is assigned to Y[19], X[1] is assigned to Y[18], X[2] is assigned to Y[17], and so on
X[19] is assigned to Y[0]. Finally print all the contents of array Y. (perform the task with
the help of for loop)

6 Write down a C program that defines an array of integers X of size 20. assign 20 integers to
X then Swap X[0] to X[19], X[1] to X[18], X[2] to X[117], and so on. (Perform the task
using for loop).

You might also like