0% found this document useful (0 votes)
2 views25 pages

Module3_TPS

This document provides an overview of arrays in C programming, including definitions, types, and methods for initialization, accessing, and manipulating one-dimensional arrays. It includes example programs for reading, displaying, searching, inserting, and deleting elements in arrays, as well as merging two arrays. Additionally, it covers searching techniques such as linear and binary search.

Uploaded by

ksparshmi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
2 views25 pages

Module3_TPS

This document provides an overview of arrays in C programming, including definitions, types, and methods for initialization, accessing, and manipulating one-dimensional arrays. It includes example programs for reading, displaying, searching, inserting, and deleting elements in arrays, as well as merging two arrays. Additionally, it covers searching techniques such as linear and binary search.

Uploaded by

ksparshmi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 25

C PROGRAMMING FOR PROBLEM SOLVING

MODULE III

ARRAYS
Introductions
Definition:
An array is a collection of elements of the same data type which is stored in consecutive
memory locations. Each data item of an array is called an element and each element is located in
separated memory location.

Each value in an array is indicated by the same name that is array name and an index which
indicates the position of value in an array. The datatype of an array can be int, float, double and
char.

Representation of index:
In the below example, ‘a’ represents the name of an array. ‘0’ to ‘4’ represents the index.
The index always begins from zero (0) and continues till (size-1) position.
Ex: int a[5];
a[0] a[1] a[2] a[3] a[4]
a

Any element in an array can be accessed using

1. Name of the array

2. Position of the element in an array.

Types of Arrays:

1. One dimensional array


2. Multidimensional array
C PROGRAMMING FOR PROBLEM SOLVING
One dimensional array(or) 1D array:
Definition:
The is the simplest type of array that contains only one row (linear list) for storing the
values of same datatype.
Declaration:
datatype array_name[size];
where datatype: type of an array.
array_name: is the name of the array that
represent the set of values.
size: the number of values that can be stored.
Ex: int a[5];
a[0] a[1] a[2] a[3] a[4]
a
Memory occupied by one dimensional array is
Total memory= (array_size) * sizeof(datatype).

Methods of initializing one dimensional array:


Initialization of array can be done in 3 ways. They are:
1. Initialize in a single statement.
2. Assigning values to each index.
3. Read input from keyboard.
Initialize in a single statement:
1. Basic Initialization:
Ex: int a[5]={10,20,30,40,50};
a[0] a[1] a[2] a[3] a[4]
a 10 20 30 40 50

2. Initialization without size:


Ex: int a[ ]={10,20,30,40,50};
a[0] a[1] a[2] a[3] a[4]
a 10 20 30 40 50

3. Partial Initialization:
Ex: int a[5]={10,20};
a[0] a[1] a[2] a[3] a[4]
a 10 20 0 0 0
C PROGRAMMING FOR PROBLEM SOLVING

4. Initialization with zero:


Ex: int a[5]={0};
a[0] a[1] a[2] a[3] a[4]
a 0 0 0 0 0

Assigning values to each index:


Initialization of elements can be done by one by one using the below syntax.
Ex: int a[5];
a[0]=10;
a[1]=20;
a[2]=30;
a[3]=40;
a[4]=50;
a[0] a[1] a[2] a[3] a[4]
a 10 20 30 40 50

Read input from keyboard:


The values to array can be read using scanf.
Syntax:
Consider an array a[n] where n value can be given directly (i.e., a[5]) or can be read using
scanf(i.e., scanf(“%d”, &n);) and ‘i’ is used to read the index values.
for(i=0;i<n;i++)
{
scanf(“%d”, &a[i]);
}

Methods of accessing one dimensional array:


C uses indexes to access individual elements in an array. Ex: To get the first element of
anarray, a[0] can be used.
To print the elements of array, individual elements (or) all the elements of an array can be
done using printf statement.

Ex:
To access individual element,
printf(“ %d”,&a[0]);
To access all the elements,
for(i=0;i<n;i++)
C PROGRAMMING FOR PROBLEM SOLVING

{
printf(“%d\t”, &a[i]); (“/t” is used to get spaces in between the elements)
}

Write a program to read and display elements of a one dimensional array.

#include<stdio.h>
main()
{
int a[10], n, i;
printf(“ Enter the size of an array”);
scanf(“%d”,&n);
printf(“ Enter the elements of an array”);
for(i=0;i<n;i++)
{
scanf(“%d”, &a[i]);
}
printf(“ The array elements are:”);
for(i=0;i<n;i++)
{
printf(“%d\t”, &a[i]);
}
}

Output:
Enter the size of an array
5
Enter the elements of an array
1 2 3 4 5
The array elements are:
1 2 3 4 5

Write a program to search an element in an array.

#include<stdio.h>
void main()
{
int i,a[20],n,key;
printf("Enter the number of
elements: ");
scanf("%d",&n);
C PROGRAMMING FOR PROBLEM SOLVING

printf("Enter the elements: ");


for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
printf("Enter the key element to be
searched: ");
scanf("%d",&key);
for(i=0;i<n;i++)
{
if(key==a[i])
printf("Element found at position %d\n",i+1);
}
}
Output:
Enter the number of elements: 5
Enter the elements: 1 2 3 4 5
Enter the key element to be searched: 5
Element found at position 5
Write a program to print the position of smallest of numbers using array.
#include<stdio.h>
void main()
{
int i,a[20],n,small,pos;
printf("Enter the number of
elements: ");
scanf("%d",&n);
printf("Enter the elements: ");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
small=a[0];
pos=0;
for(i=0;i<n;i++)
{
if(a[i]<small)
{
C PROGRAMMING FOR PROBLEM SOLVING

small=a[i];
pos=i;

}
}
printf("The smallest element is %d
and the position is
%d",small,pos+1);
}
Output:
Enter the number of elements: 5
Enter the elements: 2 3 4 5 6
The smallest element is 2 and the position is 1

Operations on array
1. Traversing an array
2. Inserting an element in an array
3. Deleting an element from an array
4. Merging 2 arrays
5. Searching an element in an array
6. Sorting an array in ascending or descending order

Traversing an array
Traversing an array means accessing each and every element of the array for a specific
purpose.
Inserting an element in an array
Inserting an element in an array means adding a new data element to an already existing
array.

Write a program to insert a number at a given location in an array.


#include<stdio.h>
void main()
{
int i,a[20],n,num,pos;
printf("Enter the number of elements: ");
scanf("%d",&n);
printf("Enter the elements: ");
C PROGRAMMING FOR PROBLEM SOLVING

for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
printf("Enter the number to be inserted: ");
scanf("%d",&num);
printf("Enter the postion at which number has to be inserted: ");
scanf("%d",&pos);
for(i=n-1;i>=pos;i--)
a[i+1]=a[i];
a[pos]=num;
n++;
printf("The array after insertion of %d is :",num);
for(i=0;i<n;i++)
printf("\t%d",a[i]);
}
Output:
Enter the number of elements: 5
Enter the elements: 1 2 4 5 6
Enter the number to be inserted: 3
Enter the postion at which number has to be inserted: 2
The array after insertion of 3 is : 1 2 3 4 5 6

Deleting an element in an array


Deleting an element from an array means removing a data element from an already existing array.

Write a program to delete a number from a given location in an array.


#include<stdio.h>
void main()
{
int i,a[20],n,pos;
printf("Enter the number of elements: ");
scanf("%d",&n);
printf("Enter the elements: ");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
printf("Enter the postion from which number has to be deleted: ");
scanf("%d",&pos);
C PROGRAMMING FOR PROBLEM SOLVING

for(i=pos;i<n-1;i++)
a[i]=a[i+1];
n--;
printf("The array after deletion is :");
for(i=0;i<n;i++)
printf("\nA[%d]=%d",i,a[i]);
}
Output:
Enter the number of elements: 5
Enter the elements: 1 2 3 4 5
Enter the postion from which number has to be deleted: 4
The array after deletion is :
A[0]=1
A[1]=2
A[2]=3
A[3]=4

Merging 2 arrays
Merging of 2 arrays in a third array means first copying the contents of the first array into the
third array and then copying the contents of second array into the third array.
Hence, the merged array contains contents of the second array.

Write a program to merge 2 unsorted arrays.


#include <stdio.h>
void main()
{
int a1[10],a2[10],a3[10],i,n1,n2,m,index=0;
printf("Enter the number of elements in array1:");
scanf("%d",&n1);
printf("Enter the elements in array1:");
for(i=0;i<n1;i++)
scanf("%d",&a1[i]);
printf("Enter the number of elements in array2:");
scanf("%d",&n2);
printf("Enter the elements in array2:");
for(i=0;i<n2;i++)
scanf("%d",&a2[i]);
m=n1+n2;
for(i=0;i<n1;i++)
{
a3[index]=a1[i];
index++;
}
for(i=0;i<n2;i++)
C PROGRAMMING FOR PROBLEM SOLVING

{
a3[index]=a2[i];
index++;
}
printf("\n\nThe merged array is\n");
for(i=0;i<m;i++)
printf("\t Arr3[%d]=%d\n",i,a3[i]);

}
Output:
Enter the number of elements in array1:3
Enter the elements in array1:1 2 3
Enter the number of elements in array2:3
Enter the elements in array2:4 5 6
The merged array is
Arr3[0]=1
Arr3[1]=2
Arr3[2]=3
Arr3[3]=4
Arr3[4]=5
Arr3[5]=6

Write a program to merge 2 sorted arrays.


#include <stdio.h>
void main()
{
int a1[10],a2[10],a3[10],i,n1,n2,m,index=0,index_1=0,index_2=0;
printf("Enter the number of elements in array1:");
scanf("%d",&n1);
printf("Enter the elements in array1:");
for(i=0;i<n1;i++)
scanf("%d",&a1[i]);
printf("Enter the number of elements in array2:");
scanf("%d",&n2);
printf("Enter the elements in array2:");
for(i=0;i<n2;i++)
scanf("%d",&a2[i]);
m=n1+n2;
while(index_1<n1&&index_2<n2)
{
if(a1[index_1]<a2[index_2])
{
a3[index]=a1[index_1];
index_1++;
C PROGRAMMING FOR PROBLEM SOLVING

}
else
{
a3[index]=a2[index_2];
index_2++;
}
index++;
}
if(index_1==n1)//if elements of the first array are over and the second array
has some elements
{
while(index_2<n2)
{
a3[index]=a2[index_2];
index_2++;
index++;
}
}
else if(index_2==n2) //if elements of the second array are over and the
first array has some elements
{
while(index_1<n1)
{
a3[index]=a1[index_1];

index_1++;
index++;
}
}
printf("\n\nThe contenets of merged array are");
for(i=0;i<m;i++)
printf("\n Arr[%d] = %d",i,a3[i]);
}
Output:
Enter the number of elements in array1:3
Enter the elements in array1:4 5 6
Enter the number of elements in array2:3
Enter the elements in array2:1 2 3
C PROGRAMMING FOR PROBLEM SOLVING

The contenets of merged array are


Arr[0] = 1
Arr[1] = 2
Arr[2] = 3
Arr[3] = 4
Arr[4] = 5
Arr[5] = 6

Searching for a value in an array


 Searching means to find whether a particular value is present in the array or
not.
 If the value is present in the array then search is said to be successful and the
search process gives the location of that array.
 If the value is not present, the search process displays the appropriate
message.
Program:
#include<stdio.h>
void main()
{
int a[10],num,i,n,found=0,pos=-1;
printf("Enter the number of elements in an array: ");
scanf("%d",&n);
printf("Enter the elements: ");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("Enter the number that has to be searched: ");
scanf("%d",&num);
for(i=0;i<n;i++)
{
if(a[i]==num)
{
found=1;
pos=i;
printf("\n%d is found in the array at position %d",num,i+1);
break;
}
C PROGRAMMING FOR PROBLEM SOLVING

}
if(found==0)
printf("Element not found in the array");
}
Output:
Enter the number of elements in an array: 5
Enter the elements: 50 9 6 7 1
Enter the number that has to be searched: 6
6 is found in the array at position 3

Binary Search:
#include<stdio.h>
void main()
{
int i,low,high,mid,n,key,a[20];
printf("Enter the number of elements in an array: ");
scanf("%d",&n);
printf("Enter the elements: ");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("Enter the value to find: ");
scanf("%d",&key);
low=0;
high=n-1;
while(low<=high)
{
mid=(low+high)/2;
if(a[mid]==key)
{
printf("%d found at location %d",key,mid+1);
break;
}
else if(a[mid]<key)
low=mid+1;
else
high=mid-1;
}
if(low>high)
C PROGRAMMING FOR PROBLEM SOLVING

printf("%d not found in the array",key);


}
Output:
Enter the number of elements in an array: 5
Enter the elements: 1 2 3 4 5
Enter the value to find: 3
3 found at location 3

Write a program to sort n numbers in ascending order using bubble sort


technique:
#include<stdio.h>
void main()
{
int i,j,n,temp,a[20];
printf("Enter the number of elements in an array: ");
scanf("%d",&n);
printf("Enter the elements: ");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<n-1;i++)
{
for(j=0;j<n-1-i;j++)
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}

}
}
printf("Array after implememting bubble sort:");
for(i=0;i<n;i++)
printf("%d\t",a[i]);
}
Output:
Enter the number of elements in an array: 5
Enter the elements: 90 7 6 100 99
C PROGRAMMING FOR PROBLEM SOLVING

Array after implememting bubble sort: 100 99 90 76

Two dimensional array(or) 1D array:


Definition:
The two dimensional array is the simplest type of the multi-dimensional array. A two
dimensional array is that which contains rows and columns for storing the values of same datatype.
Declaration:
datatype array_name[size1][size2];
where datatype: type of an array.
array_name: nameof the array to represent the set of values.
size1: the number of rows that can be stored.
Size2: the number of columns that can be stored.
Ex: int a[3][5];
a[0][0] a[0][1] a[0][2] a[0][3] a[0][4]
a[1][0] a[1][1] a[1][2] a[1][3] a[1][4]
a[2][0] a[2][1] a[2][2] a[2][3] a[2][4]

Methods of initializing one dimensional array:


Initialization of array can be done in 3 ways. They are:
1. Initialize in a single statement.
2. Assigning values to each index.
3. Read input from keyboard.
1. Initialize in a single statement:
Ex: int a[3][3]={{10,20,30},{40,50}};
10 20 30
40 50

2. Assigning values to each index:


Initialization of elements can be done by one by one using the below syntax.
Ex: int a[3][3];
a[0][0]=10;
a[0][1]=20;
a[1][0]=30;
C PROGRAMMING FOR PROBLEM SOLVING

a[1][1]=40;
10 20
30 40

3. Read input from keyboard:

The values to array can be read using scanf.


Syntax:
Consider an array a[n] where n value can be given directly (i.e., a[5]) or can be read using
scanf(i.e., scanf(“%d”, &n);) and ‘i’ is used to read the index values.
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf(“%d”, &a[i][j]);
}
}
Methods of accessing one dimensional array:
C uses indexes to access individual elements in an array. Ex: To get the one element of an
array, a[0][0] can be used.
To print the elements of array, individual elements (or) all the elements of an array can be
done using printf statement.

Ex:
To access individual element,
printf(“ %d”,a[0][1]);

To access all the elements,


for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
printf(“%d\t”, a[i][j]); //(/t is used to spaces between the numbers)
}
printf(“\n”); // (/n is used to differentiate rows and columns)
}
C PROGRAMMING FOR PROBLEM SOLVING

Write a program to read and display elements of a two dimensional array.

#include<stdio.h>
main()
{
int a[10][10],m, j, n, i;
printf(“ Enter the no of rows and columns of an array”);
scanf(“%d%d”,&m, &n);
printf(“ Enter the elements of an array”);
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf(“%d”, &a[i][j]);
}
}
printf(“ The array elements are:”);
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
printf(“%d\t”, a[i][j]);
}
printf(“\n”);
}
}

Output:
Enter the no of rows and columns of an array
2 2
Enter the elements of an array
1 2 3 4
The array elements are:
1 2
3 4

Write a program to generate Pascal’s triangle.

#include<stdio.h>
void main()
{
int a[5][5]={0},row=2,col,i,j;
a[0][0]=a[1][0]=a[1][1]=1;
C PROGRAMMING FOR PROBLEM SOLVING

while(row<5)
{
a[row][0]=1;
for(col=1;col<=row;col++)
a[row][col]=a[row-1][col-1]+a[row-1][col];
row++;

}
for(i=0;i<5;i++)
{
printf("\n");
for(j=0;j<=i;j++)
printf("%d\t",a[i][j]);
}
}
Output:
1
11
121
1331
14641

Operations on 2-Dimensional Array

1. Transpose
2. Sum
3. Difference
4. Product

Write a program to transpose 3 X 3 matrix.program

#include<stdio.h>
void main()
{
int a[20][20],m,n,i,j,b[20][20];

printf("Enter the number of rows and columns: ");


scanf("%d,%d",&m,&n);
printf("Enter the elements of the array:");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("The array elements are:\n");
C PROGRAMMING FOR PROBLEM SOLVING

for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
printf("%d\t",a[i][j]);

}
printf("\n");
}
for(i=0;i<m;i++)
{

for(j=0;j<n;j++)
{
b[i][j]=a[j][i];

}
}
printf("The elemnts of transposed matrix are:\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
printf("%d\t",b[i][j]);

}
printf("\n");
}
}
Output:
Enter the number of rows and columns: 3,3
Enter the elements of the array:1 2 3 4 5 6 7 8 9
The array elements are:
123
456
789
The elements of transposed matrix are:
147
258
369

Write a program to input 2 m x n matrices and then calculate the sum of their corresponding
elements and store it in third m x n matrix.
#include<stdio.h>
void main()
{
int a[20][20],b[20][20],c[20][20],m,n,p,q,r,t,i,j;
C PROGRAMMING FOR PROBLEM SOLVING

printf("Enter the number of rows and columns in first matrix: ");


scanf("%d,%d",&m,&n);
printf("Enter the number of rows and columns in second matrix: ");
scanf("%d,%d",&p,&q);
if(m!=p||n!=q)
{
printf("Number of rows and columns of both the matrix should be
equal");
}
r=m;
t=n;
printf("Enter the elements of the array 1:");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("Enter the elements of the array 2:");
for(i=0;i<p;i++)
{
for(j=0;j<q;j++)
{
scanf("%d",&b[i][j]);
}

}
for(i=0;i<r;i++)
{
for(j=0;j<t;j++)
{
c[i][j]=a[i][j]+b[i][j];
}
}
printf("The elements of the resultant matrix are:\n");
for(i=0;i<r;i++)
{
for(j=0;j<t;j++)
{
printf("%d\t",c[i][j]);
}
printf("\n");
}
}
Output:
Enter the number of rows and columns in first matrix: 2,2
C PROGRAMMING FOR PROBLEM SOLVING

Enter the number of rows and columns in second matrix: 2,2


Enter the elements of the array 1:2 2 2 2
Enter the elements of the array 2:2 2 2 2
The elements of the resultant matrix are:
4 4
5 4

Write a program to input 2 m x n matrices and then calculate the product of their corresponding
elements and store it in third m x n matrix.
#include<stdio.h>
void main()
{
int a[20][20],b[20][20],c[20][20],m,n,p,q,k,i,j;
printf("Enter the number of rows and columns in first matrix: ");
scanf("%d,%d",&m,&n);
printf("Enter the number of rows and columns in second matrix: ");
scanf("%d,%d",&p,&q);
if(n!=p)
{
printf("Matrix multiplication is not possible");
}
printf("Enter the elements of the array 1:");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
}

printf("Enter the elements of the array 2:");


for(i=0;i<p;i++)
{
for(j=0;j<q;j++)
{
scanf("%d",&b[i][j]);
}
}
for(i=0;i<m;i++)
{
for(j=0;j<q;j++)
{
c[i][j]=0;
for(k=0;k<n;k++)
c[i][j]=a[i][k]*b[k][j]+c[i][j];
C PROGRAMMING FOR PROBLEM SOLVING

}
}
printf("The elements of the resultant matrix are:\n");
for(i=0;i<m;i++)
{
for(j=0;j<q;j++)
{
printf("%d\t",c[i][j]);
}
printf("\n");
}
}
Output:
Enter the number of rows and columns in first matrix: 2,2
Enter the number of rows and columns in second matrix: 2,2
Enter the elements of the array 1:2 2 2 2
Enter the elements of the array 2:2 2 2 2
The elements of the resultant matrix are:
88
88

Using arrays with functions


• Putting individual elements of the array
• Passing the whole array

Passing individual elements of the array


#include<stdio.h>
void square(int x);
void main()
{
int n,a[10],i;
printf("Enter the number of elements: ");
scanf("%d",&n);
printf("Enter the elements: ");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("The square of given elements are: ");
C PROGRAMMING FOR PROBLEM SOLVING

for(i=0;i<n;i++)
square(a[i]);
}
void square(int x)
{
printf("%d\t",x*x);
return;
}
Output:
Enter the number of elements: 5
Enter the elements: 1 2 3 4 5
The square of given elements are: 1 4 9 16 25

Passing whole array


#include<stdio.h>
void avg(int a[]);
void main()
{
int b[6]={1,2,3,4,5,6};
avg(b);
}
void avg(int a[])
{
int i,Average,sum=0;
for(i=0;i<6;i++)
{
sum=sum+a[i];
}
Average=sum/6;
C PROGRAMMING FOR PROBLEM SOLVING

printf("Average=%d",Average);
}

Output:

Average=3

Multi Dimensional array

• A Multi-Dimensional array is an array of arrays.

• Like we have 1 index in 1-D array, 2 index in 2-D array, we have n index in n-dimensional
array.

Write a program to read and display 2 x 2 x 2 array.


#include<stdio.h>
void main()
{
int a[2][2][2],i,j,k;
printf("Enter the elements of the matrix: ");
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
for(k=0;k<2;k++)
{
scanf("%d",&a[i][j][k]);
}
}
}
printf("The matrix is: \n");
for(i=0;i<2;i++)
{
C PROGRAMMING FOR PROBLEM SOLVING

for(j=0;j<2;j++)
{
for(k=0;k<2;k++)
{
printf("a[%d][%d][%d]=%d\t",i,j,k,a[i][j][k]);
}
printf("\n");
}
}
}

Output:
Enter the elements of the matrix: 1 2 3 4 5 6 7 8 9
The matrix is:
a[0][0][0]=1 a[0][0][1]=2
a[0][1][0]=3 a[0][1][1]=4
a[1][0][0]=5 a[1][0][1]=6
a[1][1][0]=7 a[1][1][1]=8

Applications of array
Storing and accessing data: Arrays are used to store and retrieve data in a specific order. For
example, an array can be used to store the scores of a group of students, or the temperatures
recorded by a weather station.
• Sorting: Arrays can be used to sort data in ascending or descending order. Sorting algorithms
such as bubble sort, merge sort, and quick sort rely heavily on arrays.
• Searching: Arrays can be searched for specific elements using algorithms such as linear search
and binary search.
• Matrices: Arrays are used to represent matrices in mathematical computations such as matrix
multiplication, linear algebra, and image processing.
C PROGRAMMING FOR PROBLEM SOLVING

• Stacks and queues: Arrays are used as the underlying data structure for implementing stacks
and queues, which are commonly, used in algorithms and data structures.
• Graphs: Arrays can be used to represent graphs in computer science. Each element in the array
represents a node in the graph, and the relationships between the nodes are represented by the
values stored in the array.

You might also like