Data Structures and Algorithms Lab: C Programs, Study notes of Computer science

C programs for various data structures and algorithms lab exercises, including matrix addition, matrix multiplication, finding the transpose of a matrix, stack operations, queue operations, circular queue operations, and double hash table operations.

Typology: Study notes

2018/2019

Uploaded on 08/15/2021

abhin1182
abhin1182 🇮🇳

1 document

1 / 148

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
NAME JAINENDRA YADAV
ROLL NO. - 2001920140060
KCA253:DATA STRUCTURES & ANALYSIS OF
ALGORITHMS LAB
1.ANS :-
#include <stdio.h>
int main()
{
int m,n,c,d,k,i,j, first[10][10], second[10][10],
sum[10][10],mul[10][10];
printf("Enter the number of rows and columns of
matrix\n");
scanf("%d%d", & m, & n);
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c
pf5d
pf5e
pf5f
pf60
pf61
pf62
pf63
pf64

Partial preview of the text

Download Data Structures and Algorithms Lab: C Programs and more Study notes Computer science in PDF only on Docsity!

NAME – JAINENDRA YADAV ROLL NO. - 2001920140060 KCA253:DATA STRUCTURES & ANALYSIS OF ALGORITHMS LAB 1.ANS :- #include <stdio.h> int main() { int m,n,c,d,k,i,j, first[10][10], second[10][10], sum[10][10],mul[10][10]; printf("Enter the number of rows and columns of matrix\n"); scanf("%d%d", & m, & n);

printf("Enter the elements of first matrix\n"); for (c = 0; c < m; c++) for (d = 0; d < n; d++) scanf("%d", & first[c][d]); printf("Enter the elements of second matrix\n"); for (c = 0; c < m; c++) for (d = 0; d < n; d++) scanf("%d", & second[c][d]); printf("Sum of entered matrices:-\n"); for (c = 0; c < m; c++) { for (d = 0; d < n; d++) { sum[c][d] = first[c][d] + second[c][d]; printf("%d\t", sum[c][d]); } printf("\n"); } printf("multiply of the matrix=\n"); for(i=0;i<m;i++) { for(j=0;j<n;j++)

OUTPUT :-

2.ANS :-

#include <stdio.h> int main() { int a[10][10], transpose[10][10], r, c; printf("Enter rows and columns: "); scanf("%d %d", &r, &c); // asssigning elements to the matrix printf("\nEnter matrix elements:\n"); for (int i = 0; i < r; ++i) { for (int j = 0; j < c; ++j) { printf("Enter element a%d%d: ", i + 1, j + 1); scanf("%d", &a[i][j]); } }

for (int i = 0; i < c; ++i) for (int j = 0; j < r; ++j) { printf("%d ", transpose[i][j]); if (j == r - 1) printf("\n"); } return 0; } OUTPUT : -

3.ANS : -

#include <stdio.h>

int ITEM=0; int choice=0; TOP=-1; while(1) { /clrscr();/ printf("\nEnter Choice\n"); printf("1: display\n"); printf("2: insert (PUSH)\n"); printf("3: remove(POP)\n"); printf("4: Exit..:\n"); scanf("%d",&choice); switch(choice) {

case 1: display(STACK); break; case 2: printf("Enter Item to be insert :"); scanf("%d",&ITEM); PUSH(STACK,ITEM); break; case 3: POP(STACK); break; case 4: exit(0); default: printf("\nInvalid choice."); break;

printf("%d <-- TOP ",stack[TOP]); for(i=TOP-1;i >=0;i--) { printf("\n%d",stack[i]); } printf("\n\n"); } /* function : PUSH(), to push an item into stack. */ void PUSH(int stack[],int item) { if(TOP==MAX-1)

printf("\nSTACK is FULL CAN't ADD ITEM\n"); return; } TOP++; stack[TOP]=item; } /* function : POP(), to pop an item from stack. */ void POP(int stack[]) { int deletedItem; if(TOP==-1)

int choice;

while (1)

printf("1.Insert element to queue

\n");

printf("2.Delete element from

queue \n");

printf("3.Display all elements of

queue \n");

printf("4.Quit \n");

printf("Enter your choice : ");

scanf("%d", &choice);

switch (choice)

case 1:

insert();

break;

case 2:

delete();

break;

case 3:

display();

break;

case 4:

exit(1);

default:

printf("Wrong choice \n");

} /* End of switch */

} /* End of while */