




























































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
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
1 / 148
This page cannot be seen from the preview
Don't miss anything!





























































































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++)
#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 : -
#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)