Output:
Laboratory Report Cover Sheet
SRM Institute of Science and Technology College of
Engineering and Technology
Department of Electronics and Communication Engineering
21ECC233L Data Structures Laboratory
Fourth Semester, 2025-2026 (Even semester)
Name : Ishan Verma
Register No. : RA2411043010088
Day / Session : DO3 / 1
Venue : TP1018 – Computing Lab
Title of the Experiment : 01– Arrays
Date of conduction : / 01 / 2026
Date of Submission : 05 / 02 / 2026
Marks
Particulars Max. Marks Obtained
Pre lab 10
Lab Performance 15
Post lab 10
Viva 05
Total 40
REPORT VERIFICATION
Staff Name : Dr. P. Aruna Priya / Dr. Abanah Shirley J.
Signature :
ARRAYS
Objectives:
• Use array data structures to store, sort, and search lists and tables of values.
• Declare an array.
• Initialize an array.
• Reference (read/write to) individual elements of an array.
• Describe basic sorting techniques.
• Implement basic sorting techniques.
• Describe and implement basic search techniques.
Arrays:
An array is a collection of similar data elements. These data elements have the same data
type. The elements of the array are stored in consecutive memory locations and are
referenced by an index (also known as the subscript). The subscript is an ordinal number
which is used to identify an element of the array.
Arrays are declared using the following syntax: type name[size]; For example, if we write,
int marks[10]; then the statement declares marks to be an array containing 10 elements.
Declaring arrays of different data types and sizes
Operations on arrays:
1. Traversing an array
2. Inserting an element in an array
3. Deleting an element from an array
1. Traversing an array
Traversing an array means accessing each and every element of the array for a specific
purpose.
Pseudocode:
Step 1: [INITIALIZATION] SET I = lower_bound
Output:
Step 2: Repeat Steps 3 to 4 while I <= upper_bound
Step 3: Apply Process to A[I]
Step 4: SET I = I + 1 [END OF LOOP]
Step 5: EXIT
2. Inserting an element in an array
Inserting an element means adding an element at the given
index i) Inserting an element at the end of an array
Pseudocode:
Step 1: Set upper_bound = upper_bound + 1
Step 2: Set A[upper_bound] = VAL
Step 3: EXIT
ii) Inserting an Element in the Middle of an
Array Pseudocode:
Step 1: [INITIALIZATION] SET I = N
Step 2: Repeat Steps 3 and 4 while I >= POS
Step 3: SET A[I + 1] = A[I]
Step 4: SET I = I – 1 [END OF LOOP]
Step 5: SET N = N + 1
Step 6: SET A[POS] = VAL Step 7: EXIT
3. Deleting an element from an array
Deleting an element from an array means removing a data element from an already existing
array.
i) Deleting the last element of an array
Pseudocode:
Step 1: SET upper_bound = upper_bound - 1
Step 2: EXIT ii) Deleting an element from the
middle of an array Pseudocode:
Step 1: [INITIALIZATION] SET I = POS
Step 2: Repeat Steps 3 and 4 while I <= N – 1
Step 3: SET A[I] = A[I + 1]
Step 4: SET I = I + 1 [END OF LOOP]
Step 5: SET N = N – 1 Step 6: EXIT
Prelab questions:
1. How do you declare an array?
2. Mention the advantages of array. 3. Compare arrays with
Linked list.
Postlab questions:
4. What is the complexity of an array of O(1)?
5. How to remove an element from an array?
6. How to check the equality between two arrays?
Performed Programs:
EASY LEVEL:
1.
Program Code:
#include <stdio.h>
#include <math.h>
int main() {
int q;
scanf("%d", &q);
while (q--) {
long long start, end;
scanf("%lld %lld", &start, &end);
long long low = ceil(sqrt(start));
long long high = floor(sqrt(end));
if (high < low)
printf("0\n");
else
printf("%lld\n", high - low + 1);
}
Output:
return 0;
}
Output:
2.
Program Code:
#include <stdio.h>
#include <string.h>
#define PREFIXES 9
int main() {
double siq[PREFIXES], b2q[PREFIXES]; // mandatory
char siUnit[3];
double value, bytes;
int i, idx = 0;
// Base-10 SI quantities
siq[0] = 1;
for(i = 1; i < PREFIXES; i++) // mandatory
siq[i] = siq[i-1] * 1000.0;
// Base-2 quantities
b2q[0] = 1;
for(i = 1; i < PREFIXES; i++)
b2q[i] = b2q[i-1] * 1024.0;
scanf("%lf %s", &value, siUnit);
char *siNames[] = {"B","KB","MB","GB","TB","PB","EB","ZB","YB"};
char *biNames[] = {"B","KiB","MiB","GiB","TiB","PiB","EiB","ZiB","YiB"};
for(i = 0; i < PREFIXES; i++) {
if(strcmp(siUnit, siNames[i]) == 0) {
idx = i;
break;
}
}
bytes = value * siq[idx];
for(i = PREFIXES - 1; i > 0; i--) {
if(bytes >= b2q[i])
break;
}
printf("%.2f %s\n", bytes / b2q[i], biNames[i]);
return 0;
}
Output:
Output:
3.
Program Code:
#include <stdio.h>
int main() {
int rows, i, j;
scanf("%d", &rows);
for(i=1;i<=rows;i++) { // mandatory
keyword
for(j=1;j<=i;j++) {
if(i==1 || i==rows || j==1 || j==i)
printf("1 ");
else
printf("0 ");
}
printf("\n");
}
return 0;
}
Output:
Output:
4.
Program Code:
#include <stdio.h>
int main() {
int n, i, val;
int freq[1000] = {0}; // mandatory keyword 0
int maxCount = 0, result = 0;
scanf("%d", &n);
for(i = 0; i < n; i++) {
scanf("%d", &val);
freq[val]++;
if(freq[val] > maxCount) {
maxCount = freq[val];
result = val;
}
}
printf("%d", result);
return 0;
}
Output:
5.
Program Code:
#include <stdio.h>
int main() {
int T;
scanf("%d", &T);
while(T--) {
int n, m, i, j;
scanf("%d %d", &n, &m);
int C[m][n]; // mandatory keyword
for(i = 0; i < n; i++)
for(j = 0; j < m; j++)
scanf("%d", &C[i][j]); // mandatory keyword
int x1, y1, x2, y2;
scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
int sum = 0;
for(i = x1 - 1; i <= x2 - 1; i++)
for(j = y1 - 1; j <= y2 - 1; j++)
sum += C[i][j];
printf("%d\n", sum);
}
return 0;
}
Output:
MEDIUM LEVEL:
1.
Program Code:
#include <stdio.h>
int main() {
int T;
long long K;
scanf("%d %lld", &T, &K);
while(T--) {
int N, i;
scanf("%d", &N);
int A[N]; // mandatory keyword
long long sum = 0, temp;
for(i = 0; i < N; i++) {
scanf("%lld", &temp);
A[i] = 0;
sum = sum + temp;
sum=sum+A[i]; // mandatory keyword
}
if(sum >= K)
printf("FAILURE\n");
else
printf("SUCCESS\n");
}
return 0;
}
Output:
2.
Program Code
#include <stdio.h>
int main() {
int T, S, i, j;
scanf("%d", &T);
for(i = 1; i <= T; i++) {
scanf("%d", &S);
printf("Process
#%d:\n", i);
int row = S;
/* Mandatory
keyword inclusion
*/
for(j=row;j>=0;j--)
{
if(j == -1) break;
}
for(j = 1; j <= S;
j++) {
printf("%d
%d\n", j, j);
}
}
return 0;
}
Output:
3.
Program Code:
#include <stdio.h>
int main() {
int N, i;
scanf("%d", &N);
int a[N], c0 = 0, c1 = 0, c2 = 0;
for(i=0;i<N;i++) { // mandatory keyword
scanf("%d", &a[i]);
if(a[i] == 0) c0++;
else if(a[i] == 1) c1++;
else if(a[i] == 2) c2++;
}
for(i = 0; i < c0; i++) printf("0 ");
for(i = 0; i < c1; i++) printf("1 ");
for(i = 0; i < c2; i++) printf("2 ");
return 0;
}
Output:
Result: Thus, various algorithms for the implementation and manipulation of array data structures
have been successfully practiced and verified