0% found this document useful (0 votes)
4 views8 pages

Exercise4 Arrays1Dand2D, Multi-Dimensionalarrays, Traversal: DATE: 27.02.2025

The document outlines a C programming exercise focused on arrays, including tasks such as finding the mean value, sorting elements, implementing matrix multiplication, and identifying the largest number in an array. It explains the concepts of one-dimensional and multi-dimensional arrays, their declaration, initialization, and accessing elements. The document concludes with a rubric for evaluation and confirms successful completion of the programming tasks.

Uploaded by

Sanjai
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)
4 views8 pages

Exercise4 Arrays1Dand2D, Multi-Dimensionalarrays, Traversal: DATE: 27.02.2025

The document outlines a C programming exercise focused on arrays, including tasks such as finding the mean value, sorting elements, implementing matrix multiplication, and identifying the largest number in an array. It explains the concepts of one-dimensional and multi-dimensional arrays, their declaration, initialization, and accessing elements. The document concludes with a rubric for evaluation and confirms successful completion of the programming tasks.

Uploaded by

Sanjai
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/ 8

DATE:​ 27.02.

2025
EXERCISE4
ARRAYS1DAND2D,MULTI-DIMENSIONALARRAYS,
TRAVERSAL

Aim:
TodevelopsolutionsforthegivenproblemusingarraysinC
GivenProblem:
Develop C program for the following:
1.​ Tofindmeanvalueofarray.
2.​ Tosorttheelementsofanarrayinascendingorder.
3.​ Toimplementthematrixmultiplication.
4.​ Tofindthebiggestnumberin array.

ConceptsInvolved:
Arrays:
CArrayisacollectionofvariablesbelongingstothesamedatatype.Youcanstoregroup of data of
same data type in an array.
Arraymightbebelongingtoanyofthedatatypes Array
size must be a constant value.
Always,Contiguous(adjacent)memorylocationsareusedtostorearrayelements in
memory.
Itisabestpracticetoinitializeanarraytozeroornullwhiledeclaring,ifwedon‟t assign
any values to array.
Declaration
dataTypearrayName[arraySize];

For example,
float mark[5];

Here, we declared an array, mark, of floating-point type. And its size is 5.


Meaning, it can hold 5 floating-point values. It's important to note that the size and typeof
an array cannot be changed once it is declared.

Accessing of Array Elements


Youcanaccesselementsofanarraybyindices.
Supposeyoudeclaredanarraymarkasabove.Thefirstelementismark[0],the second
element is mark[1] and so on.
●​ Arrayshave0asthefirstindex,not1.Inthisexample,mark[0]isthefirst
element.
●​ Ifthesizeofanarrayisn,toaccessthelastelement,then-1indexisused.In this
example, mark[4]

●​ Suppose the starting address of mark[0] is 2120d. Then,theaddressofthe


mark[1]willbe2124d.Similarly,theaddressofmark[2]will be 2128d andsoon.
This is because the size of a float is 4 bytes.

Initialization
Itispossibletoinitializeanarray during
declaration. For example,
int mark[5] = {19, 10, 8, 17, 9};
Youcanalsoinitialize
anarraylike
this. int
mark[] =
{19, 10, 8,
17, 9};
Here, we haven't specified the size.
However,thecompiler knowsitssize is5as weareinitializing itwith5 elements.

ChangeValueofArrayelements
int mark[5] = {19, 10, 8, 17, 9}

//makethevalueofthe
third element to -1
mark[2] = -1;

//makethevalueofthe
fifth element to 0
mark[4] = 0;

TYPES OF C ARRAYS:
Thereare2typesofCarrays.Theyare,
1.​ One dimensional array
2.​ Multi dimensional array
●​ Twodimensionalarray
●​ Three dimensional array
●​ four dimensional array etc…
1.​ ONE DIMENSIONAL ARRAY:
Syntax : data-type arr_name[array_size];
Array declaration syntax: data_type arr_name [arr_size];
Array initialization syntax: data_type arr_name [arr_size]=(value1, value2,
value3,….);
Array accessing syntax: arr_name[index];
2.​ TWO DIMENSIONAL ARRAY:
●​ Twodimensionalarrayisnothingbutarrayof array.
●​ syntax : data_type array_name[num_of_rows][num_of_column];

Array declaration syntax:


data_type arr_name [num_of_rows][num_of_column];
Array initialization syntax:
data_type arr_name[2][2] = {{0,0},{0,1},{1,0},{1,1}};
Arra
y
accessin
g syntax:
arr_name
[index];

Integer array example:


int arr[2][2];
int arr[2][2] = {1,2, 3, 4};
arr [0] [0] = 1;
arr [0] ]1] = 2;
arr [1][0] = 3;
arr [1] [1] = 4;
1.

OUTPUT:
2.

OUTPUT:
Output:
4.

Output:
RUBRICS MARKS

DOCUMENTPRESENTATION 15

TIMELYSUBMISSION 10

TOTAL 25

Result:
Thus,developedsolutions andprogrammed succesfully forthe given problem
using arrays in C programming language

You might also like