File: ~/pro01.c Page 1 of 2 #include <stdio.h> #include <stdlib.h> #include <string.h> struct Day { char *dayName; // dynamically allocated string int date; char *activity; // dynamically allocated string }; struct Day *create() { // Create dynamic array of 7 days struct Day *week = ( struct Day *)malloc(7 * sizeof ( struct Day)); if (week == NULL) { printf("Memory Allocation Failed!\n"); exit(0); } return week; } void read( struct Day *week) { char temp[100]; printf("\nEnter the Weekly Calendar Details:\n"); for ( int i = 0; i < 7; i++) { printf("\n--- Day %d ---\n", i + 1); // Read day name printf("Enter Day Name: "); scanf("%s", temp); week[i].dayName = ( char *)malloc(strlen(temp) + 1); strcpy(week[i].dayName, temp); // Read date printf("Enter Date (number): "); scanf("%d", &week[i].date); // Read activity description printf("Enter Activity Description: "); getchar(); // to clear newline fgets(temp, sizeof (temp), stdin); temp[strcspn(temp, "\n")] = 0; // remove newline week[i].activity = ( char *)malloc(strlen(temp) + 1); strcpy(week[i].activity, temp); } } void display( struct Day *week) { printf("\n\n===== WEEKLY ACTIVITY REPORT =====\n"); for ( int i = 0; i < 7; i++) { printf("\nDay %d: %s\n", i + 1, week[i].dayName); printf("Date: %d\n", week[i].date); printf("Activity: %s\n", week[i].activity); } } int main() { struct Day *week; week = create(); // Create dynamic array of 7 days read(week); // Read all values from the user display(week); // Display the full weekly report // Free allocated memory after usage for ( int i = 0; i < 7; i++) { File: ~/pro01.c Page 2 of 2 free(week[i].dayName); free(week[i].activity); } free(week); return 0; } File: ~/pro02.c Page 1 of 1 #include <stdio.h> #include <string.h> void removeNewline( char *str) { size_t len = strlen(str); if (len > 0 && str[len - 1] == '\n') str[len - 1] = '\0'; } int main() { char STR[200], PAT[50], REP[50], RESULT[300]; int i, j, k, found = 0; printf("Enter Main String (STR): "); fgets(STR, sizeof (STR), stdin); removeNewline(STR); printf("Enter Pattern String (PAT): "); fgets(PAT, sizeof (PAT), stdin); removeNewline(PAT); printf("Enter Replace String (REP): "); fgets(REP, sizeof (REP), stdin); removeNewline(REP); int lenSTR = strlen(STR); int lenPAT = strlen(PAT); int lenREP = strlen(REP); i = j = 0; while (i < lenSTR) { k = 0; // Check if PAT matches STR starting at position i while (k < lenPAT && STR[i + k] == PAT[k]) { k++; } // If complete PAT is matched if (k == lenPAT) { found = 1; // Copy REP to RESULT strcpy(&RESULT[j], REP); j += lenREP; // Move i forward by length of PAT i += lenPAT; } else { // Copy current character RESULT[j++] = STR[i++]; } } RESULT[j] = '\0'; if (!found) { printf("\nPattern does NOT exist in the main string.\n"); } else { printf("\nThe new string after replacement is:\n%s\n", RESULT); } return 0; } File: ~/pro03.c Page 1 of 2 #include<stdio.h> #include<stdlib.h> #define MAX 3 int s[MAX]; int top = -1; void push( int item); int pop(); void palindrome(); void display(); void main() { int choice, item; while (1) { printf("\n\n\n\n-----------Menu----------- : "); printf("\n=>1.Push an Element to Stack and Overflow demo "); printf("\n=>2.Pop an Element from Stack and Underflow demo"); printf("\n=>3.Palindrome demo "); printf("\n=>4.Display "); printf("\n=>5.Exit"); printf("\nEnter your choice: "); scanf("%d", & choice); switch (choice) { case 1: printf("\nEnter an element to be pushed: "); scanf("%d", & item); push(item); break ; case 2: item = pop(); if (item != -1) printf("\nElement popped is: %d", item); break ; case 3: palindrome(); break ; case 4: display(); break ; case 5: exit(1); default : printf("\nPlease enter valid choice "); break ; } } } void push( int item) { if (top == MAX - 1) { printf("\n-----------Stack overflow-----------"); return ; } top = top + 1; s[top] = item; } File: ~/pro03.c Page 2 of 2 int pop() { int item; if (top == -1) { printf("\n-----------Stack underflow-----------"); return -1; } item = s[top]; top = top - 1; return item; } void display() { int i; if (top == -1) { printf("\n-----------Stack is empty-----------"); return ; } printf("\nStack elements are:\n "); for (i = top; i >= 0; i--) printf("| %d |\n", s[i]); } void palindrome() { int flag = 1, i; printf("\nStack content are:\n"); for (i = top; i >= 0; i--) printf("| %d |\n", s[i]); printf("\nReverse of stack content are:\n"); for (i = 0; i <= top; i++) printf("| %d |\n", s[i]); for (i = 0; i <= top / 2; i++) { if (s[i] != s[top - i]) { flag = 0; break ; } } if (flag == 1) { printf("\nIt is palindrome number"); } else { printf("\nIt is not a palindrome number"); } } File: ~/pro04.c Page 1 of 2 #include<stdio.h> #include<stdlib.h> void evaluate(); void push( char ); char pop(); int prec( char ); char infix[30], postfix[30], stack[30]; int top = -1; void main() { printf("\n Enter the valid infix expression:"); scanf("%s", infix); evaluate(); printf("\nThe entered infix expression is :\n %s \n", infix); printf("\nThe corresponding postfix expression is :\n %s \n", postfix); } void evaluate() { int i = 0, j = 0; char symb, temp; push('#'); for (i = 0; infix[i] != '\0'; i++) { symb = infix[i]; switch (symb) { case '(': push(symb); break ; case ')': temp = pop(); while (temp != '(') { postfix[j] = temp; j++; temp = pop(); } break ; case '+': case '-': case '*': case '/': case '%': case '^': case '$': while (prec(stack[top]) >= prec(symb)) { temp = pop(); postfix[j] = temp; j++; } push(symb); break ; default : postfix[j] = symb; j++; } } File: ~/pro04.c Page 2 of 2 while (top > 0) { temp = pop(); postfix[j] = temp; j++; } postfix[j] = '\0'; } void push( char item) { top = top + 1; stack[top] = item; } char pop() { char item; item = stack[top]; top = top - 1; return item; } int prec( char symb) { int p; switch (symb) { case '#': p = -1; break ; case '(': case ')': p = 0; break ; case '+': case '-': p = 1; break ; case '*': case '/': case '%': p = 2; break ; case '^': case '$': p = 3; break ; } return p; } File: ~/pro05.c Page 1 of 1 #include<stdio.h> #include<stdlib.h> #include<math.h> #include<ctype.h> int i, top = -1; int op1, op2, res, s[20]; char postfix[90], symb; void push( int item) { top = top + 1; s[top] = item; } int pop() { int item; item = s[top]; top = top - 1; return item; } void main() { printf("\nEnter a valid postfix expression:\n"); scanf("%s", postfix); for (i = 0; postfix[i] != '\0'; i++) { symb = postfix[i]; if (isdigit(symb)) { push(symb - '0'); } else { op2 = pop(); op1 = pop(); switch (symb) { case '+': push(op1 + op2); break ; case '-': push(op1 - op2); break ; case '*': push(op1 * op2); break ; case '/': push(op1 / op2); break ; case '%': push(op1 % op2); break ; case '$': case '^': push(pow(op1, op2)); break ; default : push(0); } } } res = pop(); printf("\n Result = %d", res); } File: ~/pro05b.c Page 1 of 1 #include <stdio.h> #include <math.h> // <-- ADD THIS void tower( int n, char source, char temp, char destination) { if (n == 0) return ; tower(n - 1, source, destination, temp); printf("\nMove disc %d from %c to %c", n, source, destination); tower(n - 1, temp, source, destination); } void main() { int n; printf("\nEnter the number of discs: \n"); scanf("%d", &n); tower(n, 'A', 'B', 'C'); printf("\n\nTotal Number of moves are: %d", ( int )pow(2, n) - 1); } File: ~/pro06.c Page 1 of 2 #include <stdio.h> #include <stdlib.h> #define MAX 5 char circular_queue[MAX]; int front = -1, rear = -1; int isEmpty() { return (front == -1 && rear == -1); } int isFull() { return ((rear + 1) % MAX == front); } void insertElement( char element) { if (isFull()) { printf("Circular Queue Overflow\n"); return ; } else if (isEmpty()) { front = rear = 0; } else { rear = (rear + 1) % MAX; } circular_queue[rear] = element; } void deleteElement() { if (isEmpty()) { printf("Circular Queue Underflow\n"); return ; } else if (front == rear) { front = rear = -1; } else { front = (front + 1) % MAX; } } void display() { if (isEmpty()) { printf("Circular Queue is empty\n"); return ; } printf("Circular Queue elements: "); int i = front; while (1) { File: ~/pro06.c Page 2 of 2 printf("%c ", circular_queue[i]); if (i == rear) break ; i = (i + 1) % MAX; } printf("\n"); } int main() { int choice; char element; do { printf("\n\n---- Circular Queue Menu ----\n"); printf("1. Insert an Element\n"); printf("2. Delete an Element\n"); printf("3. Display Circular Queue\n"); printf("4. Exit\n"); printf("Enter your choice: "); scanf("%d", &choice); switch (choice) { case 1: printf("Enter element to be inserted: "); scanf(" %c", &element); insertElement(element); break ; case 2: deleteElement(); break ; case 3: display(); break ; case 4: printf("Exiting...\n"); break ; default : printf("Invalid choice! Please enter a valid option.\n"); } } while (choice != 4); return 0; } File: ~/pro07.c Page 1 of 4 #include<stdio.h> #include<stdlib.h> struct node { char usn[25], name[50], branch[50]; int sem; long long phone; struct node *link; }; typedef struct node* NODE; NODE start = NULL; int count = 0; NODE create() { NODE temp = (NODE)malloc( sizeof ( struct node)); if (temp == NULL) { printf("\nMemory not available"); exit(1); } printf("\nEnter USN: "); scanf(" %[^\n]", temp->usn); printf("Enter Name: "); scanf(" %[^\n]", temp->name); printf("Enter Branch: "); scanf(" %[^\n]", temp->branch); printf("Enter Semester: "); scanf("%d", &temp->sem); printf("Enter Phone Number: "); scanf("%lld", &temp->phone); temp->link = NULL; count++; return temp; } NODE insertfront() { NODE temp = create(); if (start == NULL) return temp; temp->link = start; return temp; } NODE deletefront() { if (start == NULL) { printf("\nLinked list is empty"); return NULL; } NODE temp = start; if (start->link == NULL) { printf("\nStudent node with USN %s deleted", start->usn); free(start); count--; return NULL; } File: ~/pro07.c Page 2 of 4 start = start->link; printf("\nStudent node with USN %s deleted", temp->usn); free(temp); count--; return start; } NODE insertend() { NODE temp = create(); if (start == NULL) return temp; NODE cur = start; while (cur->link != NULL) cur = cur->link; cur->link = temp; return start; } NODE deleteend() { if (start == NULL) { printf("\nLinked List is empty"); return NULL; } if (start->link == NULL) { printf("\nStudent node with USN %s deleted", start->usn); free(start); count--; return NULL; } NODE prev = NULL, cur = start; while (cur->link != NULL) { prev = cur; cur = cur->link; } printf("\nStudent node with USN %s deleted", cur->usn); free(cur); prev->link = NULL; count--; return start; } void display() { if (start == NULL) { printf("\nNo contents to display\n"); return ; } NODE cur = start; int num = 1; printf("\n----- SLL Contents -----\n"); while (cur != NULL) { printf("\n[%d] USN:%s | Name:%s | Branch:%s | Sem:%d | Phone:%lld", num, cur->usn, cur->name, cur->branch, cur->sem, cur->phone); cur = cur->link; num++; } File: ~/pro07.c Page 3 of 4 printf("\n\nTotal student nodes = %d\n", count); } void stackdemo() { int ch; while (1) { printf("\n------- STACK DEMO (Front In/Out) -------\n"); printf("1. Push (Insert at Front)\n"); printf("2. Pop (Delete at Front)\n"); printf("3. Display\n"); printf("4. Exit Stack Demo\n"); printf("Enter your choice: "); scanf("%d", &ch); switch (ch) { case 1: start = insertfront(); break ; case 2: start = deletefront(); break ; case 3: display(); break ; case 4: return ; default : printf("\nInvalid choice\n"); } } } int main() { int ch, n, i; while (1) { printf("\n------------ MENU ------------\n"); printf("1. Create SLL of Student Nodes\n"); printf("2. Display Status\n"); printf("3. Insert at End\n"); printf("4. Delete at End\n"); printf("5. Stack Demo (Insert/Delete Front)\n"); printf("6. Exit\n"); printf("Enter your choice: "); scanf("%d", &ch); switch (ch) { case 1: printf("\nEnter number of students: "); scanf("%d", &n); for (i = 0; i < n; i++) start = insertfront(); break ; case 2: display(); break ; case 3: start = insertend(); break ; case 4: start = deleteend(); break ; case 5: stackdemo(); break ; case 6: exit(0); default : File: ~/pro07.c Page 4 of 4 printf("\nInvalid choice! Try again.\n"); } } } File: ~/pro08.c Page 1 of 4 #include<stdio.h> #include<stdlib.h> struct node { char ssn[25], name[25], dept[10], designation[25]; int sal; long int phone; struct node *llink; struct node *rlink; }; typedef struct node * NODE; NODE first = NULL; int count = 0; NODE create() { NODE enode = (NODE)malloc( sizeof ( struct node)); if (enode == NULL) { printf("\nRunning out of memory"); exit(0); } printf("\nEnter SSN: "); scanf("%s", enode->ssn); printf("Enter Name: "); scanf("%s", enode->name); printf("Enter Department: "); scanf("%s", enode->dept); printf("Enter Designation: "); scanf("%s", enode->designation); printf("Enter Salary: "); scanf("%d", &enode->sal); printf("Enter Phone Number: "); scanf("%ld", &enode->phone); enode->llink = NULL; enode->rlink = NULL; count++; return enode; } NODE insertfront() { NODE temp = create(); if (first == NULL) return temp; temp->rlink = first; first->llink = temp; return temp; } NODE insertend() { NODE temp = create(); File: ~/pro08.c Page 2 of 4 if (first == NULL) return temp; NODE cur = first; while (cur->rlink != NULL) cur = cur->rlink; cur->rlink = temp; temp->llink = cur; return first; } NODE deletefront() { if (first == NULL) { printf("\nDLL is empty"); return NULL; } NODE temp = first; if (first->rlink == NULL) // only one node { printf("\nDeleted Employee SSN: %s", first->ssn); free(first); count--; return NULL; } first = first->rlink; first->llink = NULL; printf("\nDeleted Employee SSN: %s", temp->ssn); free(temp); count--; return first; } NODE deleteend() { if (first == NULL) { printf("\nDLL is empty"); return NULL; } if (first->rlink == NULL) // only 1 node { printf("\nDeleted Employee SSN: %s", first->ssn); free(first); count--; return NULL; } NODE cur = first; while (cur->rlink != NULL) cur = cur->rlink; printf("\nDeleted Employee SSN: %s", cur->ssn); cur->llink->rlink = NULL; free(cur); File: ~/pro08.c Page 3 of 4 count--; return first; } void display() { NODE cur = first; if (cur == NULL) { printf("\nNo contents to display in DLL\n"); return ; } int nodeno = 1; printf("\nEmployee DLL contents:\n"); while (cur != NULL) { printf("\nNode:%d | SSN:%s | Name:%s | Dept:%s | Desig:%s | Salary:%d | Phone: %ld", nodeno, cur->ssn, cur->name, cur->dept, cur->designation, cur->sal, cur->phone); cur = cur->rlink; nodeno++; } printf("\nTotal Employees = %d\n", count); } void deqdemo() { int ch; while (1) { printf("\n--- Double Ended Queue Demo ---\n"); printf("1. Insert Front\n2. Delete Front\n3. Insert Rear\n4. Delete Rear\n5. Display\n6. Exit\n"); printf("Enter choice: "); scanf("%d", &ch); switch (ch) { case 1: first = insertfront(); break ; case 2: first = deletefront(); break ; case 3: first = insertend(); break ; case 4: first = deleteend(); break ; case 5: display(); break ; default : return ; } } } int main() { int ch, n, i; while (1) { printf("\n--------- MENU ---------\n"); printf("1. Create DLL\n"); printf("2. Display DLL\n"); printf("3. Insert End\n"); printf("4. Delete End\n"); File: ~/pro08.c Page 4 of 4 printf("5. Insert Front\n"); printf("6. Delete Front\n"); printf("7. Deque Demo\n"); printf("8. Exit\n"); printf("Enter choice: "); scanf("%d", &ch); switch (ch) { case 1: printf("\nEnter no of employees: "); scanf("%d", &n); for (i = 1; i <= n; i++) first = insertend(); break ; case 2: display(); break ; case 3: first = insertend(); break ; case 4: first = deleteend(); break ; case 5: first = insertfront(); break ; case 6: first = deletefront(); break ; case 7: deqdemo(); break ; case 8: exit(0); default : printf("\nInvalid choice\n"); } } } File: ~/pro09.c Page 1 of 2 #include <stdio.h> #include <math.h> struct poly { int coef; int px, py, pz; }; void readPoly( struct poly P[], int n) { for ( int i = 0; i < n; i++) { printf("\tEnter the %d term:\n", i + 1); printf("\t\tCoef = "); scanf("%d", &P[i].coef); printf("\t\tEnter Pow(x) Pow(y) and Pow(z): "); scanf("%d %d %d", &P[i].px, &P[i].py, &P[i].pz); } } void printPoly( struct poly P[], int n) { for ( int i = 0; i < n; i++) { printf("%dx^%dy^%dz^%d", P[i].coef, P[i].px, P[i].py, P[i].pz); if (i != n - 1) printf(" + "); } printf("\n"); } int evaluate( struct poly P[], int n, int x, int y, int z) { int sum = 0; for ( int i = 0; i < n; i++) { sum += P[i].coef * pow(x, P[i].px) * pow(y, P[i].py) * pow(z, P[i].pz); } return sum; } int main() { int choice; do { printf("\n--------Menu--------\n"); printf("1.Represent and Evaluate a Polynomial P(x,y,z)\n"); printf("2.Find the sum of two polynomials POLY1(x,y,z) and POLY2(x,y,z)\n"); printf("Enter your choice: "); scanf("%d", &choice); if (choice == 1) { int n, x, y, z; struct poly P[20]; printf("\n----Polynomial evaluation P(x,y,z)----\n"); printf("Enter the no of terms in the polynomial: "); scanf("%d", &n); readPoly(P, n); printf("\nRepresentation of Polynomial for evaluation:\n"); printPoly(P, n); printf("\nEnter the value of x,y and z: "); scanf("%d %d %d", &x, &y, &z); int result = evaluate(P, n, x, y, z); printf("Result of polynomial evaluation is : %d\n", result); } else if (choice == 2) {