You are on page 1of 12

BONAFIDE CERTIFICATE

Registration No. RA2211026030017

Certified to be the bonafide record of work done by Tanishq Anand Of IIIrd semester, IInd year
B.TECH degree course in SRM INSTITUTE OF SCIENCE & TECHNOLOGY, DELHI-NCR
Campus for the Department of Computer Science &Engineering, in data structures and
algorithms Laboratory, during the academic year 2023-24.

Faculty-In-Charge Head of the department

Submitted for IIIrd semester examination held on / / at


SRM INSTITUTE OF SCIENCE & TECHNOLOGY, DELHI-NCR Campus.
Internal Examiner-I Internal Examiner-II
INDEX

Expt. Name of Expt. Pg. DOE DOC Sign.


No. No.
1. Matrix multiplication 3-4

2. Linear Search 5-6

3. Binary Search 7-8

4. Insertion sort 9-10

5. Bubble Sort 11-12

6.

7.

8.

9.

10.

11.
Ex. No.: 1 Matrix Multiplication
Date :

Aim: To complete a matrix multiplication of 3 x 3 matrix

Source Code:

#include<stdio.h>
int main()
{
int i,j,k;
int a[3][3], b[3][3], mul[3][3];
printf("Enter elements of first matrix:\n");
for(i=0;i< 3;i++)
{
for(j=0;j< 3;j++)
{
printf("a[%d][%d]=",i,j);
scanf("%d", &a[i][j]);
}
}
printf("Enter elements of second matrix:\n");
for(i=0;i< 3;i++)
{
for(j=0;j< 3;j++)
{
printf("b[%d][%d]=",i,j);
scanf("%d", &b[i][j]);
}
}
for(i=0;i< 3;i++)
{
for(j=0;j< 3;j++)
{
mul[i][j] = 0;
for(k=0;k< 3;k++)
{
mul[i][j] = mul[i][j] + a[i][k]*b[k][j];
}}}
printf("Multiplied matrix is:\n");
for(i=0;i< 3;i++)
{
for(j=0;j< 3;j++)
{
printf("%d\t", mul[i][j]);
}
printf("\n");
}
return 0;}
OUTPUT

RESULT

The program was compiled and executed successfully.


Ex. No.: 2 Linear search
Date :

Aim: To do a linear search in a given array

Source Code:
#include<stdio.h>
int main()
{
int a[100],j,k,l,f=0,s;
printf("Enter size");
scanf("%d",&s);
printf("Enter the elemets of array\n");
for(j=0;j<s;j++)
{
printf("Enter element at a[%d] ",j);
scanf("%d",&a[j]);
}
printf("the elements are :");
for(j=0;j<s;j++)
{
printf(" %d",a[j]);
}
printf("Enter the element to be searched: \n");
scanf("%d",&k);
for (j=0;j<s;j++)
{
if(a[j]==k)
{f=1;
printf("Element %d found at a[%d]",k,j);
break;
}}

if(!f)
{printf("Element %d not found",k);
}
return 0;
}
OUTPUT
Ex. No.:3 Binary Search

Date :

Aim: To search an element in an array using Binary search method

Source Code:

#include<stdio.h>
int main()
{
int ar[100],n,x,i,a,b,c,d=0;
printf("Enter size of array\n");
scanf("%d",&n);
printf("enter the e;ements\n");
for(i=0; i<n; i++)
{ printf("Enter element\n");
scanf("%d",&ar[i]);}
printf("Enter element to be search\n");
scanf("%d",&x);
a=0;
b=n-1;
while(a<=b)
{ c=(a+b)/2;
if(ar[c]==x)
{
printf("Element found at %d :",c+1);
d=1;
break;
}if(ar[c]>x)
b=c-1;
else
a=c+1;}
if(!d)
printf("No element\n");
return 0;
}
OUTPUT
Ex. No.:4 Insertion sorting
Date:

Aim: To sort the array by insertion sorting

Source Code:

#include <stdio.h>
int main()
{
int n,a[100],b,c,t,f= 0;
printf("Enter no. of elements\n");
scanf("%d",&n);
printf("Enter %d no.\n", n);
for (b=0;b<n;b++)
scanf("%d", &a[b]);
for (b=1;b<=n-1;b++) {
t = a[b];
for (c=b-1;c>=0;c--) {
if (a[c]>t) {
a[c+1]=a[c];
f=1;
}
else
break;}
if (f)
a[c+1] = t;}
printf("Sorted list in ascending order:\n");
for (b=0;b<=n-1;b++) {
printf("%d\n", a[b]);}
return 0;
}
OUTPUT
Ex. No.:5 BUBBLE SORT
Date:

Aim: To sort an array by bubble sorting.

Source Code:
#include <stdio.h>
int main()
{
int a[100],n,c,d,swap;
printf("Enter no. of elements\n");
scanf("%d", &n);
printf("Enter %d no.s \n", n);
for (c = 0; c < n; c++)
scanf("%d", &a[c]);
for (c=0;c<n-1;c++)
{ for (d=0;d<n-c-1;d++){
if (a[d]>a[d+1])
{
swap = a[d];
a[d]=a[d+1];
a[d+1]=swap;
}}}
printf("Sorted list in ascending order:\n");
for (c=0;c<n;c++)
printf("%d\n", a[c]);
return 0;
}
OUTPUT

You might also like