maths
maths
maths
h>
#include <stdlib.h>
#include <string.h>
struct Day {
char *name;
int date;
char *description;
};
if (calendar == NULL) {
exit(1);
// Initialize each day with dynamic memory for name and description
return calendar;
int main() {
int numDays = 7;
strcpy(myCalendar[0].name, "Sunday");
myCalendar[0].date = 1;
myCalendar[1].date = 2;
free(myCalendar[i].name);
free(myCalendar[i].description);
free(myCalendar);
return 0;
#include <stdlib.h>
#include <string.h>
#define MAX_DAYS 7
struct Day {
char *name;
int date;
char *description;
};
if (calendar == NULL) {
exit(1);
scanf("%s", calendar[i].name);
scanf("%d", &calendar[i].date);
int main() {
readData(myCalendar);
displayCalendar(myCalendar);
free(myCalendar[i].name);
free(myCalendar[i].description);
free(myCalendar);
return 0; {
3 . #include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct Stack {
int top;
int arr[MAX_SIZE];
};
stack->top = -1;
return stack;
if (isFull(stack)) {
printf("Stack Overflow\n");
return;
stack->arr[++stack->top] = item;
}
// Function to pop an element from the stack
if (isEmpty(stack)) {
printf("Stack Underflow\n");
return -1;
return stack->arr[stack->top--];
push(stack, str[i]);
// If the string has odd number of characters, skip the middle character
if (len % 2 != 0) {
mid++;
if (str[i] != pop(stack)) {
return 1; // Palindrome
if (isEmpty(stack)) {
printf("Stack is empty\n");
return;
printf("Stack: ");
printf("\n");
int main() {
char str[100];
do {
printf("\nStack Operations\n");
printf("1. Push\n");
printf("2. Pop\n");
printf("4. Display\n");
printf("5. Exit\n");
scanf("%d", &choice);
switch (choice) {
case 1:
scanf("%d", &item);
push(stack, item);
break;
case 2:
item = pop(stack);
if (item != -1) {
break;
case 3:
scanf("%s", str);
if (isPalindrome(str)) {
} else {
break;
case 4:
display(stack);
break;
case 5:
printf("Exiting...\n");
break;
default:
printf("Invalid choice\n");
return 0;
4 . #include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct Stack {
int top;
char arr[MAX_SIZE];
};
stack->top = -1;
return stack;
if (isFull(stack)) {
printf("Stack Overflow\n");
return;
stack->arr[++stack->top] = item;
if (isEmpty(stack)) {
printf("Stack Underflow\n");
return -1;
return stack->arr[stack->top--];
switch (op) {
case '+':
case '-':
return 1;
case '*':
case '/':
case '%':
return 2;
case '^':
return 3;
default:
return -1;
int i, j;
if (isalnum(infix[i])) {
postfix[j++] = infix[i];
} else if (infix[i] == '(') {
push(stack, '(');
postfix[j++] = pop(stack);
printf("Invalid Expression\n");
return;
} else {
} else if (isOperator(infix[i])) {
postfix[j++] = pop(stack);
push(stack, infix[i]);
while (!isEmpty(stack)) {
postfix[j++] = pop(stack);
postfix[j] = '\0';
int main() {
scanf("%s", infix);
infixToPostfix(infix, postfix);
return 0;
5 . #include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
struct Stack {
int top;
int arr[MAX_SIZE];
};
stack->top = -1;
return stack;
if (isFull(stack)) {
printf("Stack Overflow\n");
return;
stack->arr[++stack->top] = item;
if (isEmpty(stack)) {
printf("Stack Underflow\n");
return -1;
return stack->arr[stack->top--];
int i;
if (isdigit(exp[i])) {
} else {
switch (exp[i]) {
case '+':
break;
case '-':
push(stack, val2 - val1);
break;
case '*':
break;
case '/':
break;
case '%':
break;
case '^':
break;
return pop(stack);
if (n == 0) {
return;
int main() {
return 0;
6 . #include <stdio.h>
#include <stdlib.h>
#define MAX 5
struct CQueue {
char items[MAX];
};
q->front = -1;
q->rear = -1;
return q;
if (isFull(q)) {
printf("Queue Overflow\n");
return;
if (isEmpty(q)) {
q->front = q->rear = 0;
} else {
q->items[q->rear] = item;
if (isEmpty(q)) {
printf("Queue Underflow\n");
return '\0';
if (q->front == q->rear) {
} else {
return item;
if (isEmpty(q)) {
printf("Queue is empty\n");
return;
}
printf("Queue: ");
int i = q->front;
do {
i = (i + 1) % MAX;
printf("\n");
int main() {
int choice;
char item;
do {
printf("1. Enqueue\n");
printf("2. Dequeue\n");
printf("3. Display\n");
printf("4. Exit\n");
scanf("%d", &choice);
switch (choice) {
case 1:
enqueue(q, item);
break;
case 2:
item = dequeue(q);
if (item != '\0') {
break;
case 3:
display(q);
break;
case 4:
printf("Exiting...\n");
break;
default:
printf("Invalid choice\n");
return 0;
11 . #include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
struct Graph {
};
graph->V = V;
graph->adj[i][j] = 0;
}
return graph;
graph->adj[src][dest] = 1;
// graph->adj[dest][src] = 1;
printf("\n");
bool visited[graph->V];
visited[i] = false;
int queue[graph->V];
visited[startVertex] = true;
queue[++rear] = startVertex;
visited[j] = true;
queue[++rear] = j;
printf("\n");
visited[vertex] = true;
DFSUtil(graph, j, visited);
bool visited[graph->V];
visited[i] = false;
return false;
return true;
int main() {
scanf("%d", &V);
scanf("%d", &E);
printf("\nAdjacency Matrix:\n");
printGraph(graph);
scanf("%d", &src);
BFS(graph, src);
if (isConnected(graph)) {
} else {
return 0;