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

Data Structure using C Assignment pdf meet saini

The document outlines a series of experiments related to data structures using C programming, specifically focusing on array manipulation. It includes aims and code for inserting, searching, updating, deleting, and sorting elements in an array. Each experiment is accompanied by a program and expected output.

Uploaded by

ATOMIC GAMER
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Data Structure using C Assignment pdf meet saini

The document outlines a series of experiments related to data structures using C programming, specifically focusing on array manipulation. It includes aims and code for inserting, searching, updating, deleting, and sorting elements in an array. Each experiment is accompanied by a program and expected output.

Uploaded by

ATOMIC GAMER
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

Manav Rachna International Institute of Research

and Studies Bachelors in Computer Applications


Data Structures using C

Submitted by: Meet Saini


Department: School of
Computer Applications Course:
Bachelors in Computer
Applications
Roll No: 24/SCA/BCA/072
Semester: 2nd
Subject: Data Structures using C
Experiment
no: 1

Aim: To insert elements in an


array.

Program
:

#include<stdio.h
> int main(){
int arr[10],
n;
printf("Enter the number of elements you
want.\n"); scanf("%d", &n);

printf("Enter the
elements.\n"); for(int i=0;

i<n; i++){ scanf("%d",

} &arr[i]);

printf("Elements inside
array are:\n"); for(int i=0;
i<n; i++){
printf("%d\t", arr[i]);

}
return 0;
}

Output
:
Experiment
no: 2

Aim: To search for element inside of an


array.

Program
:

#include<stdio.h>
int main(){ int arr[7]
=
{1,5,3,7,6,4,9};
int n, count=0;

printf("Enter the element that you want to


search.\n"); scanf("%d", &n);

for(int i=0; i<7; i++){ if(arr[i] == n)


{ printf("%d is present at %d position\n",
n, i+1);
count += 1;
}
}
if(count == 0){
printf("%d not found.\n");
} return
0; }

Output
:
Experiment
no: 3

Aim: To update element in an


array.

Program
:

#include<stdio.h>
int main(){ int arr[7]
=
{1,2,3,4,5,6,7};
int pos, n;

printf("Elements of array
before updation.\n"); for(int i=0;
i<7; i++){ printf("%d\t", arr[i]);
}

printf("\nEnter the position of element you


want to update.\n"); scanf("%d", &pos);

printf("Enter the value you


want to update.\n");
scanf("%d", &n);

arr[pos-1] // Updating
= n;
t
h
e

e
l
e
m
e
n
t
.
printf("Elements of array after
updation.\n"); for(int i=0; i<7; i+
+){ printf("%d\t", arr[i]); }
return 0; }

Output
:
Experiment no: 4 Aim: To
delete element from an array.

Program
:

#include<stdio.h>
int main(){ int arr[7]
=
{1,2,3,4,5,6,7}; int n,
count=0;

printf("Elements of array
before deletion:\n"); for(int i=0;
i<7; i++){ printf("%d\t", arr[i]);
}

printf("\nEnter the element that you want to


delete.\n"); scanf("%d", &n);

for(int i=0; i<7; i++)


{ if(arr[i] == n){
count += 1;
for(int j=i; j<6; j++){
arr[j] = arr[j+1];
} } } if(count == 0){ printf("%d not
found\n", n); } else{ printf("Elements
of array after deletion:\n"); for(int
i=0; i<6; i++){ printf("%d\t", arr[i]); }
}
return 0;
} Output:
Experiment no: 5 Aim: To
sort elements in an array.

Program
:

#include<stdio.h>
int main(){ int arr[7]
=
{4,2,6,8,5,1,9}; int temp;

printf("Initial Array:\
n"); for(int i=0; i<7;
i++){ printf("%d\t",
arr[i]);
}

printf("\nSorting in ascending
order:\n");

for(int i=0; i<7; i++)


{ for(int j=0;
j<6; j++){
if(arr[j] >
arr[j+1]){
temp =
arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
}

for(int i=0; i<7; i++)


{ printf("%d\t",
arr[i]); }

printf("\nSorting in descending
order:\n");

for(int i=0; i<7; i++)


{ for(int j=0;
j<6; j++){
if(arr[j] <
arr[j+1]){
temp =
arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
}

for(int i=0; i<7; i++)


{ printf("%d\t",
arr[i]); }
retur
n
0; }

Output
:

You might also like