Assignment (DSA)
Assignment (DSA)
2)
Write user defined program for following and compile the programs and attach the screenshot of output
after each program (any four)
Ans:
Program:
#include <stdio.h>
int main() {
int size;
// Input the size of the array
printf("Enter the number of element in the array : ");
scanf("%d",&size);
int arr[size];
return 0;
}
Output:
Q2. Write a C program to compute the transpose of a 2-D array.
Ans:
Program:
#include<stdio.h>
int main() {
int rows, cols;
int array[rows][cols];
int transposed[cols][rows];
typedef struct {
int items[MAX];
int top;
} Stack;
// Function to initialize the stack
void initialize(Stack *s) {
s->top = -1;
}
int main() {
Stack s;
initialize(&s);
int choice, value;
while (1)
{
printf("\nStack Menu\n");
printf("1. Push\n");
printf("2. Pop\n");
printf("3. Peek\n");
printf("4. Check if Empty\n");
printf("5. Check if Full\n");
printf("6. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice)
{
case 1:
printf("Enter the value to Push: ");
scanf("%d", &value);
push(&s, value);
break;
case 2:
value = pop(&s);
if (value != -1) {
printf("Popped %d from the stack\n",value);
}
break;
case 3:
value = peek(&s);
if (value != -1) {
printf("Top element is %d\n",value);
}
break;
case 4:
if (isEmpty(&s)) {
printf("Stack is empty\n");
} else {
printf("Stack is notEmpty");
}
break;
case 5:
if (isFull(&s)) {
printf("Stack is Full\n");
} else {
printf("Stack is not Full");
}
break;
case 6:
exit(0);
default:
printf("Invalid choice\n");
break;
}
}
return 0;
}
Output:
Q3. Write a C program to implement a stack using array.
Ans:
Program
#include<stdio.h>
int main() {
int n, i;
int arr[n];
return 0;
}
Output: