ar
Feedback
C Programming Codes

C Programming Codes

الذهاب إلى القناة على Telegram

C Programming Codes || Quizzes || DSA Learn along with the community Any queries admin - @Pradeep_saii

إظهار المزيد

📈 نظرة تحليلية على قناة تيليجرام C Programming Codes

تُعد قناة C Programming Codes (@c_programming_codes) في القطاع اللغوي الإنكليزية لاعباً نشطاً. يضم المجتمع حالياً 13 433 مشتركاً، محتلاً المرتبة 9 525 في فئة التكنولوجيات والتطبيقات والمرتبة 32 112 في منطقة الهند.

📊 مؤشرات الجمهور والحراك

منذ تأسيسه في невідомо، حقق المشروع نمواً سريعاً وجمع 13 433 مشتركاً.

بحسب آخر البيانات بتاريخ 10 يونيو, 2026، تحافظ القناة على نشاط مستقر. خلال آخر 30 يوماً تغيّر عدد الأعضاء بمقدار -232، وفي آخر 24 ساعة بمقدار -3، مع بقاء الوصول العام مرتفعاً.

  • حالة التحقق: غير موثّقة
  • معدل التفاعل (ER): يبلغ متوسط تفاعل الجمهور 9.77‎%. وخلال أول 24 ساعة من النشر يحصد المحتوى عادةً N/A‎% من ردود الفعل نسبةً إلى إجمالي المشتركين.
  • وصول المنشورات: يحصل كل منشور على متوسط 0 مشاهدة. وخلال اليوم الأول يجمع عادةً 0 مشاهدة.
  • التفاعلات والاستجابة: يتفاعل الجمهور بانتظام؛ متوسط التفاعلات لكل منشور يبلغ 0.
  • الاهتمامات الموضوعية: يركز المحتوى على مواضيع رئيسية مثل input, string, scanf("%d, array, element.

📝 الوصف وسياسة المحتوى

يصف المؤلف القناة بأنها مساحة للتعبير عن الآراء الذاتية:
C Programming Codes || Quizzes || DSA Learn along with the community Any queries admin - @Pradeep_saii

بفضل وتيرة التحديث المرتفعة (أحدث البيانات بتاريخ 11 يونيو, 2026) تحافظ القناة على حداثتها ومستوى وصول مرتفع. وتُظهر التحليلات تفاعلاً نشطاً من الجمهور، ما يجعلها نقطة تأثير مهمة ضمن فئة التكنولوجيات والتطبيقات.

13 433
المشتركون
-324 ساعات
-477 أيام
-23230 أيام
أرشيف المشاركات
💻 Implement Circular Queue
#include <stdio.h>
#include <stdlib.h>

#define MAX_SIZE 5

int queue[MAX_SIZE];
int front = -1;
int rear = -1;

void enqueue(int value) {
    if ((rear + 1) % MAX_SIZE == front) {
        printf("Queue is fulln");
        return;
    } else if (front == -1) {
        front = 0;
        rear = 0;
    } else {
        rear = (rear + 1) % MAX_SIZE;
    }
    queue[rear] = value;
    printf("Inserted %dn", value);
}

int dequeue() {
    int value;
    if (front == -1) {
        printf("Queue is emptyn");
        return -1;
    }

    value = queue[front];
    if (front == rear) {
        front = -1;
        rear = -1;
    } else {
        front = (front + 1) % MAX_SIZE;
    }
    printf("Deleted %dn", value);
    return value;
}

void display() {
    int i;
    if (front == -1) {
        printf("Queue is emptyn");
        return;
    }
    printf("Queue elements are:n");
    for (i = front; i != rear; i = (i + 1) % MAX_SIZE)
        printf("%d ", queue[i]);
    printf("%d ", queue[rear]);
    printf("n");
}

int main() {
    int choice, value;

    while (1) {
        printf("1. Enqueuen");
        printf("2. Dequeuen");
        printf("3. Displayn");
        printf("4. Exitn");
        printf("Enter your choice: ");
        scanf("%d", &choice);

        switch (choice) {
            case 1:
                printf("Enter value to enqueue: ");
                scanf("%d", &value);
                enqueue(value);
                break;
            case 2:
                dequeue();
                break;
            case 3:
                display();
                break;
            case 4:
                exit(0);
            default:
                printf("Invalid choicen");
        }
    }

    return 0;
}
📤 Output:
1. Enqueue
2. Dequeue
3. Display
4. Exit
Enter your choice: Input: 1
Enter value to enqueue: Input: 10
Output: Inserted 10
1. Enqueue
2. Dequeue
3. Display
4. Exit
Enter your choice: Input: 1
Enter value to enqueue: Input: 20
Output: Inserted 20
1. Enqueue
2. Dequeue
3. Display
4. Exit
Enter your choice: Input: 1
Enter value to enqueue: Input: 30
Output: Inserted 30
1. Enqueue
2. Dequeue
3. Display
4. Exit
Enter your choice: Input: 1
Enter value to enqueue: Input: 40
Output: Inserted 40
1. Enqueue
2. Dequeue
3. Display
4. Exit
Enter your choice: Input: 1
Enter value to enqueue: Input: 50
Output: Inserted 50
1. Enqueue
2. Dequeue
3. Display
4. Exit
Enter your choice: Input: 1
Enter value to enqueue: Input: 60
Output: Queue is full
1. Enqueue
2. Dequeue
3. Display
4. Exit
Enter your choice: Input: 3
Output: Queue elements are:
10 20 30 40 50
1. Enqueue
2. Dequeue
3. Display
4. Exit
Enter your choice: Input: 2
Output: Deleted 10
1. Enqueue
2. Dequeue
3. Display
4. Exit
Enter your choice: Input: 3
Output: Queue elements are:
20 30 40 50
1. Enqueue
2. Dequeue
3. Display
4. Exit
Enter your choice: Input: 1
Enter value to enqueue: Input: 60
Output: Inserted 60
1. Enqueue
2. Dequeue
3. Display
4. Exit
Enter your choice: Input: 3
Output: Queue elements are:
20 30 40 50 60
1. Enqueue
2. Dequeue
3. Display
4. Exit
Enter your choice: Input: 2
Output: Deleted 20
1. Enqueue
2. Dequeue
3. Display
4. Exit
Enter your choice: Input: 2
Output: Deleted 30
1. Enqueue
2. Dequeue
3. Display
4. Exit
Enter your choice: Input: 2
Output: Deleted 40
1. Enqueue
2. Dequeue
3. Display
4. Exit
Enter your choice: Input: 2
Output: Deleted 50
1. Enqueue
2. Dequeue
3. Display
4. Exit
Enter your choice: Input: 2
Output: Deleted 60
1. Enqueue
2. Dequeue
3. Display
4. Exit
Enter your choice: Input: 3
Output: Queue is empty
1. Enqueue
2. Dequeue
3. Display
4. Exit
Enter your choice: Input: 2
Output: Queue is empty
1. Enqueue
2. Dequeue
3. Display
4. Exit
Enter your choice: Input: 4

💻 Implement Queue Using Linked List
#include <stdio.h>
#include <stdlib.h>

typedef struct Node {
    int data;
    struct Node* next;
} Node;

typedef struct Queue {
    Node* front;
    Node* rear;
} Queue;

Queue* createQueue() {
    Queue* q = (Queue*)malloc(sizeof(Queue));
    if (q == NULL) {
        printf("Memory allocation failedn");
        exit(EXIT_FAILURE);
    }
    q->front = q->rear = NULL;
    return q;
}

void enqueue(Queue* q, int data) {
    Node* newNode = (Node*)malloc(sizeof(Node));
    if (newNode == NULL) {
        printf("Memory allocation failedn");
        exit(EXIT_FAILURE);
    }
    newNode->data = data;
    newNode->next = NULL;

    if (q->rear == NULL) {
        q->front = q->rear = newNode;
        return;
    }

    q->rear->next = newNode;
    q->rear = newNode;
}

int dequeue(Queue* q) {
    if (q->front == NULL) {
        printf("Queue is emptyn");
        return -1;
    }

    Node* temp = q->front;
    int data = temp->data;

    q->front = q->front->next;

    if (q->front == NULL) {
        q->rear = NULL;
    }

    free(temp);
    return data;
}

int isEmpty(Queue* q) {
    return (q->front == NULL);
}

void displayQueue(Queue* q) {
    Node* current = q->front;
    if (current == NULL) {
        printf("Queue is emptyn");
        return;
    }
    printf("Queue elements: ");
    while (current != NULL) {
        printf("%d ", current->data);
        current = current->next;
    }
    printf("n");
}

int main() {
    Queue* q = createQueue();

    enqueue(q, 10);
    enqueue(q, 20);
    enqueue(q, 30);

    displayQueue(q);

    printf("Dequeued: %dn", dequeue(q));
    printf("Dequeued: %dn", dequeue(q));

    displayQueue(q);

    if (isEmpty(q)) {
        printf("Queue is emptyn");
    } else {
        printf("Queue is not emptyn");
    }

    printf("Dequeued: %dn", dequeue(q));

    if (isEmpty(q)) {
        printf("Queue is emptyn");
    } else {
        printf("Queue is not emptyn");
    }
     dequeue(q);

    return 0;
}
📤 Output:
Queue elements: 10 20 30
Dequeued: 10
Dequeued: 20
Queue elements: 30
Queue is not empty
Dequeued: 30
Queue is empty
Queue is empty

💻 Implement Queue Using Array
#include <stdio.h>
#include <stdlib.h>

#define MAX_SIZE 100

int queue[MAX_SIZE];
int front = -1;
int rear = -1;

void enqueue(int value) {
  if (rear == MAX_SIZE - 1) {
    printf("Queue is full!n");
  } else {
    if (front == -1)
      front = 0;
    rear++;
    queue[rear] = value;
    printf("Inserted %d into queuen", value);
  }
}

void dequeue() {
  if (front == -1 || front > rear) {
    printf("Queue is empty!n");
  } else {
    printf("Deleted element: %dn", queue[front]);
    front++;
  }
}

void display() {
  if (front == -1) {
    printf("Queue is empty!n");
  } else {
    printf("Queue elements are:n");
    for (int i = front; i <= rear; i++)
      printf("%d ", queue[i]);
    printf("n");
  }
}

int main() {
  int choice, value;
  while (1) {
    printf("1. Enqueuen");
    printf("2. Dequeuen");
    printf("3. Displayn");
    printf("4. Exitn");
    printf("Enter your choice: ");
    scanf("%d", &choice);

    switch (choice) {
      case 1:
        printf("Enter value to enqueue: ");
        scanf("%d", &value);
        enqueue(value);
        break;
      case 2:
        dequeue();
        break;
      case 3:
        display();
        break;
      case 4:
        exit(0);
      default:
        printf("Wrong choicen");
    }
  }
  return 0;
}
📤 Output:
1. Enqueue
2. Dequeue
3. Display
4. Exit
Enter your choice: Input: 1
Enter value to enqueue: Input: 10
Inserted 10 into queue
1. Enqueue
2. Dequeue
3. Display
4. Exit
Enter your choice: Input: 1
Enter value to enqueue: Input: 20
Inserted 20 into queue
1. Enqueue
2. Dequeue
3. Display
4. Exit
Enter your choice: Input: 3
Queue elements are:
10 20
1. Enqueue
2. Dequeue
3. Display
4. Exit
Enter your choice: Input: 2
Deleted element: 10
1. Enqueue
2. Dequeue
3. Display
4. Exit
Enter your choice: Input: 3
Queue elements are:
20
1. Enqueue
2. Dequeue
3. Display
4. Exit
Enter your choice: Input: 2
Deleted element: 20
1. Enqueue
2. Dequeue
3. Display
4. Exit
Enter your choice: Input: 3
Queue is empty!
1. Enqueue
2. Dequeue
3. Display
4. Exit
Enter your choice: Input: 2
Queue is empty!
1. Enqueue
2. Dequeue
3. Display
4. Exit
Enter your choice: Input: 4

🔧 Data Structures - Queue

💻 Sort a Stack Using Temporary Stack
#include <stdio.h>
#include <stdlib.h>

struct Stack {
    int top;
    unsigned capacity;
    int *array;
};

struct Stack* createStack(unsigned capacity) {
    struct Stack* stack = (struct Stack*) malloc(sizeof(struct Stack));
    stack->capacity = capacity;
    stack->top = -1;
    stack->array = (int*) malloc(stack->capacity * sizeof(int));
    return stack;
}

int isFull(struct Stack* stack) {
    return stack->top == stack->capacity - 1;
}

int isEmpty(struct Stack* stack) {
    return stack->top == -1;
}

void push(struct Stack* stack, int item) {
    if (isFull(stack))
        return;
    stack->array[++stack->top] = item;
}

int pop(struct Stack* stack) {
    if (isEmpty(stack))
        return -1; // or some error value
    return stack->array[stack->top--];
}

int peek(struct Stack* stack) {
    if (isEmpty(stack))
        return -1; // or some error value
    return stack->array[stack->top];
}

void sortStack(struct Stack* stack) {
    struct Stack* tempStack = createStack(stack->capacity);
    int tmp;

    while (!isEmpty(stack)) {
        tmp = pop(stack);

        while (!isEmpty(tempStack) && peek(tempStack) > tmp) {
            push(stack, pop(tempStack));
        }

        push(tempStack, tmp);
    }

    while (!isEmpty(tempStack)) {
        push(stack, pop(tempStack));
    }
    free(tempStack->array);
    free(tempStack);
}

int main() {
    struct Stack* stack = createStack(5);
    push(stack, 5);
    push(stack, 2);
    push(stack, 4);
    push(stack, 1);
    push(stack, 3);

    sortStack(stack);

    printf("Sorted stack: ");
    while (!isEmpty(stack)) {
        printf("%d ", pop(stack));
    }
    printf("n");
    free(stack->array);
    free(stack);

    return 0;
}
📤 Output:
Sorted stack: 1 2 3 4 5

💻 Check if Stack is Sorted
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

#define MAX_SIZE 100

struct Stack {
    int arr[MAX_SIZE];
    int top;
};

void initialize(struct Stack *stack) {
    stack->top = -1;
}

bool isEmpty(struct Stack *stack) {
    return stack->top == -1;
}

bool isFull(struct Stack *stack) {
    return stack->top == MAX_SIZE - 1;
}

void push(struct Stack *stack, int value) {
    if (isFull(stack)) {
        printf("Stack Overflown");
        return;
    }
    stack->arr[++stack->top] = value;
}

int pop(struct Stack *stack) {
    if (isEmpty(stack)) {
        printf("Stack Underflown");
        return -1;
    }
    return stack->arr[stack->top--];
}

bool isStackSorted(struct Stack *stack) {
    if (isEmpty(stack) || stack->top == 0) {
        return true;
    }

    struct Stack tempStack;
    initialize(&tempStack);
    int temp;
    bool sorted = true;

    while (!isEmpty(stack)) {
        temp = pop(stack);

        if (!isEmpty(&tempStack) && tempStack.arr[tempStack.top] < temp) {
            sorted = false;
            break;
        }

        while (!isEmpty(&tempStack) && tempStack.arr[tempStack.top] < temp) {
            push(stack, pop(&tempStack));
        }
        push(&tempStack, temp);
    }

    while (!isEmpty(&tempStack)) {
        push(stack, pop(&tempStack));
    }

    return sorted;
}

int main() {
    struct Stack myStack;
    initialize(&myStack);

    push(&myStack, 5);
    push(&myStack, 4);
    push(&myStack, 3);
    push(&myStack, 2);
    push(&myStack, 1);

    if (isStackSorted(&myStack)) {
        printf("Stack is sorted.n");
    } else {
        printf("Stack is not sorted.n");
    }

    return 0;
}
📤 Output:
Stack is sorted.

💻 Implement Two Stacks in One Array
#include <stdio.h>
#include <stdlib.h>

#define SIZE 10

int array[SIZE];
int top1 = -1;
int top2 = SIZE;

void push1(int data) {
    if (top1 < top2 - 1) {
        top1++;
        array[top1] = data;
    } else {
        printf("Stack 1 is fulln");
    }
}

void push2(int data) {
    if (top1 < top2 - 1) {
        top2--;
        array[top2] = data;
    } else {
        printf("Stack 2 is fulln");
    }
}

int pop1() {
    if (top1 >= 0) {
        int popped = array[top1];
        top1--;
        return popped;
    } else {
        printf("Stack 1 is emptyn");
        return -1;
    }
}

int pop2() {
    if (top2 < SIZE) {
        int popped = array[top2];
        top2++;
        return popped;
    } else {
        printf("Stack 2 is emptyn");
        return -1;
    }
}

int main() {
    push1(10);
    push1(20);
    push2(30);
    push2(40);

    printf("Popped from Stack 1: %dn", pop1());
    printf("Popped from Stack 2: %dn", pop2());

    return 0;
}
📤 Output:
Popped from Stack 1: 20
Popped from Stack 2: 40

💻 Reverse a List Using Stack
#include <stdio.h>
#include <stdlib.h>

#define MAX_SIZE 100

struct Stack {
    int top;
    int items[MAX_SIZE];
};

void initialize(struct Stack *s) {
    s->top = -1;
}

int isEmpty(struct Stack *s) {
    return (s->top == -1);
}

int isFull(struct Stack *s) {
    return (s->top == MAX_SIZE - 1);
}

void push(struct Stack *s, int data) {
    if (isFull(s)) {
        printf("Stack Overflow n");
        return;
    }
    s->items[++s->top] = data;
}

int pop(struct Stack *s) {
    if (isEmpty(s)) {
        printf("Stack Underflow n");
        return -1;
    }
    return s->items[s->top--];
}

int main() {
    struct Stack s;
    initialize(&s);
    int n, i, num;

    printf("Enter the number of elements in the list: ");
    scanf("%d", &n);

    int list[n];

    printf("Enter the elements of the list:n");
    for (i = 0; i < n; i++) {
        scanf("%d", &list[i]);
    }

    for (i = 0; i < n; i++) {
        push(&s, list[i]);
    }

    printf("Reversed List:n");
    for (i = 0; i < n; i++) {
        list[i] = pop(&s);
        printf("%d ", list[i]);
    }
    printf("n");

    return 0;
}
📤 Output:
Input: 5
Input: 1
Input: 2
Input: 3
Input: 4
Input: 5
Output: Enter the number of elements in the list: Enter the elements of the list:
Reversed List:
5 4 3 2 1

💻 Reverse a String Using Stack
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#define MAX_SIZE 100

struct Stack {
    char items[MAX_SIZE];
    int top;
};

void initialize(struct Stack *s) {
    s->top = -1;
}

int isEmpty(struct Stack *s) {
    return (s->top == -1);
}

int isFull(struct Stack *s) {
    return (s->top == MAX_SIZE - 1);
}

void push(struct Stack *s, char c) {
    if (isFull(s)) {
        printf("Stack Overflown");
        return;
    }
    s->items[++s->top] = c;
}

char pop(struct Stack *s) {
    if (isEmpty(s)) {
        printf("Stack Underflown");
        return '0';
    }
    return s->items[s->top--];
}

int main() {
    char str[MAX_SIZE];
    struct Stack s;
    initialize(&s);

    printf("Enter a string: ");
    scanf("%s", str);

    int len = strlen(str);

    for (int i = 0; i < len; i++) {
        push(&s, str[i]);
    }

    printf("Reversed string: ");
    for (int i = 0; i < len; i++) {
        printf("%c", pop(&s));
    }
    printf("n");

    return 0;
}
📤 Output:
Input: hello
Output: Enter a string: Reversed string: olleh

💻 Stock Span Problem
#include <stdio.h>
#include <stdlib.h>

int main() {
    int n;
    printf("Enter the number of days: ");
    scanf("%d", &n);

    int prices[n];
    printf("Enter the stock prices for each day:n");
    for (int i = 0; i < n; i++) {
        scanf("%d", &prices[i]);
    }

    int span[n];
    for (int i = 0; i < n; i++) {
        span[i] = 1; // Initialize span to 1
        for (int j = i - 1; j >= 0 && prices[j] <= prices[i]; j--) {
            span[i]++;
        }
    }

    printf("Stock Span values:n");
    for (int i = 0; i < n; i++) {
        printf("%d ", span[i]);
    }
    printf("n");

    return 0;
}
📤 Output:
Input: 7
Input: 100
Input: 80
Input: 60
Input: 70
Input: 60
Input: 75
Input: 85
Output: Enter the number of days: Enter the stock prices for each day:
Stock Span values:
1 1 1 2 1 4 6

💻 Next Smaller Element
#include <stdio.h>
#include <stdlib.h>

int main() {
    int n;
    printf("Enter the number of elements: ");
    scanf("%d", &n);

    int arr[n];
    printf("Enter the elements:n");
    for (int i = 0; i < n; i++) {
        scanf("%d", &arr[i]);
    }

    int nextSmaller[n];
    for (int i = 0; i < n; i++) {
        nextSmaller[i] = -1;
        for (int j = i + 1; j < n; j++) {
            if (arr[j] < arr[i]) {
                nextSmaller[i] = arr[j];
                break;
            }
        }
    }

    printf("Next Smaller Element:n");
    for (int i = 0; i < n; i++) {
        printf("%d ", nextSmaller[i]);
    }
    printf("n");

    return 0;
}
📤 Output:
Input: 5
Input: 5
Input: 4
Input: 3
Input: 2
Input: 1
Output: Enter the number of elements: Enter the elements:
Next Smaller Element:
4 3 2 1 -1
Input: 4
Input: 1
Input: 3
Input: 2
Input: 4
Output: Enter the number of elements: Enter the elements:
Next Smaller Element:
-1 2 -1 -1

💻 Next Greater Element
#include <stdio.h>
#include <stdlib.h>

int main() {
    int n;

    printf("Enter the number of elements: ");
    scanf("%d", &n);

    int arr[n];
    printf("Enter the elements:n");
    for (int i = 0; i < n; i++) {
        scanf("%d", &arr[i]);
    }

    int nextGreater[n];
    for (int i = 0; i < n; i++) {
        nextGreater[i] = -1;
    }

    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            if (arr[j] > arr[i]) {
                nextGreater[i] = arr[j];
                break;
            }
        }
    }

    printf("Next Greater Elements are:n");
    for (int i = 0; i < n; i++) {
        printf("%d ", nextGreater[i]);
    }
    printf("n");

    return 0;
}
📤 Output:
Input: 5
Input: 16 7 2 8 9
Output: Enter the number of elements: Enter the elements:
Next Greater Elements are:
-1 8 8 9 -1

💻 Evaluate Prefix Expression
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

#define MAX_SIZE 100

int stack[MAX_SIZE];
int top = -1;

void push(int value) {
    stack[++top] = value;
}

int pop() {
    return stack[top--];
}

int evaluatePrefix(char* expression) {
    int i, operand1, operand2, result;
    for (i = strlen(expression) - 1; i >= 0; i--) {
        if (isdigit(expression[i])) {
            push(expression[i] - '0');
        } else {
            operand1 = pop();
            operand2 = pop();
            switch (expression[i]) {
                case '+':
                    result = operand1 + operand2;
                    break;
                case '-':
                    result = operand1 - operand2;
                    break;
                case '*':
                    result = operand1 * operand2;
                    break;
                case '/':
                    result = operand1 / operand2;
                    break;
                default:
                    printf("Invalid operatorn");
                    return -1;
            }
            push(result);
        }
    }
    return pop();
}

int main() {
    char expression[MAX_SIZE];

    printf("Enter prefix expression: ");
    scanf("%s", expression);

    int result = evaluatePrefix(expression);

    if (result != -1) {
        printf("Result: %dn", result);
    }

    return 0;
}
📤 Output:
Input: +*234
Output: Result: 10

Input: -+*23/825
Output: Result: 6

💻 Evaluate Postfix Expression
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

#define MAX_SIZE 100

int stack[MAX_SIZE];
int top = -1;

void push(int value) {
    stack[++top] = value;
}

int pop() {
    return stack[top--];
}

int evaluatePostfix(char* expression) {
    int i = 0;
    while (expression[i] != '0') {
        if (isdigit(expression[i])) {
            int num = 0;
            while(isdigit(expression[i])){
                num = num * 10 + (expression[i] - '0');
                i++;
            }
            i--;
            push(num);
        } else if (expression[i] == '+' || expression[i] == '-' ||
                   expression[i] == '*' || expression[i] == '/') {
            int operand2 = pop();
            int operand1 = pop();
            switch (expression[i]) {
                case '+':
                    push(operand1 + operand2);
                    break;
                case '-':
                    push(operand1 - operand2);
                    break;
                case '*':
                    push(operand1 * operand2);
                    break;
                case '/':
                    push(operand1 / operand2);
                    break;
            }
        }
        i++;
    }
    return pop();
}

int main() {
    char expression[MAX_SIZE];

    printf("Enter postfix expression: ");
    scanf("%s", expression);

    int result = evaluatePostfix(expression);
    printf("Result: %dn", result);

    return 0;
}
📤 Output:
Input: 23+
Output: Result: 5
Input: 123+*
Output: Result: 6
Input: 567*+
Output: Result: 47
Input: 102/
Output: Result: 5
Input: 53-
Output: Result: 2
Input: 105+2*
Output: Result: 30
Input: 231*+9-
Output: Result: -4
Input: 123+4*+
Enter postfix expression: 123+4*+
Result: 20

💻 Infix to Prefix Conversion
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

#define MAX_SIZE 100

char stack[MAX_SIZE];
int top = -1;

void push(char c) {
    if (top == MAX_SIZE - 1) {
        printf("Stack Overflown");
        return;
    }
    stack[++top] = c;
}

char pop() {
    if (top == -1) {
        return -1; // Indicates an empty stack
    }
    return stack[top--];
}

int precedence(char operator) {
    switch (operator) {
        case '+':
        case '-':
            return 1;
        case '*':
        case '/':
            return 2;
        case '^':
            return 3;
        default:
            return 0;
    }
}

void reverseString(char *str) {
    int len = strlen(str);
    for (int i = 0, j = len - 1; i < j; i++, j--) {
        char temp = str[i];
        str[i] = str[j];
        str[j] = temp;
    }
}

void infixToPrefix(char *infix, char *prefix) {
    int i, j = 0;
    int len = strlen(infix);

    reverseString(infix);

    for (i = 0; i < len; i++) {
        if (infix[i] == '(') {
            infix[i] = ')';
        } else if (infix[i] == ')') {
            infix[i] = '(';
        }
    }

    for (i = 0; i < len; i++) {
        if (isalnum(infix[i])) {
            prefix[j++] = infix[i];
        } else if (infix[i] == '(') {
            push(infix[i]);
        } else if (infix[i] == ')') {
            while (top != -1 && stack[top] != '(') {
                prefix[j++] = pop();
            }
            if (top != -1 && stack[top] == '(') {
                pop();
            }
        } else {
            while (top != -1 && precedence(infix[i]) <= precedence(stack[top])) {
                prefix[j++] = pop();
            }
            push(infix[i]);
        }
    }

    while (top != -1) {
        prefix[j++] = pop();
    }

    prefix[j] = '0';
    reverseString(prefix);
}

int main() {
    char infix[MAX_SIZE];
    char prefix[MAX_SIZE];

    printf("Enter infix expression: ");
    scanf("%s", infix);

    infixToPrefix(infix, prefix);

    printf("Prefix expression: %sn", prefix);

    return 0;
}
📤 Output:
Input: a+b*c
Output: Prefix expression: +a*bc

Input: (a+b)*c
Output: Prefix expression: *+abc

Input: a+b*(c^d-e)^(f+g*h)-i
Output: Prefix expression: -+a*b^-^cde+f*ghi

Input: A*(B+C)/D
Output: Prefix expression: /*A+BCD

💻 Infix to Postfix Conversion
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

#define MAX_SIZE 100

char stack[MAX_SIZE];
int top = -1;

void push(char item) {
  stack[++top] = item;
}

char pop() {
  if (top == -1) {
    return -1;
  }
  return stack[top--];
}

int precedence(char operator) {
  switch (operator) {
    case '+':
    case '-':
      return 1;
    case '*':
    case '/':
      return 2;
    case '^':
      return 3;
    default:
      return 0;
  }
}

int main() {
  char infix[MAX_SIZE], postfix[MAX_SIZE];
  int i, j = 0;

  printf("Enter infix expression: ");
  scanf("%s", infix);

  for (i = 0; infix[i] != '0'; i++) {
    if (isalnum(infix[i])) {
      postfix[j++] = infix[i];
    } else if (infix[i] == '(') {
      push(infix[i]);
    } else if (infix[i] == ')') {
      while (top != -1 && stack[top] != '(') {
        postfix[j++] = pop();
      }
      pop(); // Remove the '('
    } else {
      while (top != -1 && precedence(infix[i]) <= precedence(stack[top])) {
        postfix[j++] = pop();
      }
      push(infix[i]);
    }
  }

  while (top != -1) {
    postfix[j++] = pop();
  }

  postfix[j] = '0';

  printf("Postfix expression: %sn", postfix);

  return 0;
}
📤 Output:
Input: a+b*c
Output: abc*+
Input: (a+b)*c
Output: ab+c*
Input: a+b*(c^d-e)^(f+g*h)-i
Output: abcd^e-fgh*+^*+i-
Input: a*b+c/d
Output: ab*cd/+
Input: a^b^c
Output: abc^^

💻 Check for Balanced Brackets
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX_SIZE 100

typedef struct {
    char data[MAX_SIZE];
    int top;
} Stack;

void initialize(Stack *stack) {
    stack->top = -1;
}

int isEmpty(Stack *stack) {
    return stack->top == -1;
}

int isFull(Stack *stack) {
    return stack->top == MAX_SIZE - 1;
}

void push(Stack *stack, char c) {
    if (!isFull(stack)) {
        stack->data[++stack->top] = c;
    }
}

char pop(Stack *stack) {
    if (!isEmpty(stack)) {
        return stack->data[stack->top--];
    }
    return '0';
}

int isMatchingPair(char character1, char character2) {
    if (character1 == '(' && character2 == ')')
        return 1;
    else if (character1 == '{' && character2 == '}')
        return 1;
    else if (character1 == '[' && character2 == ']')
        return 1;
    else
        return 0;
}

int isBalanced(char *expression) {
    Stack stack;
    initialize(&stack);
    int i;
    for (i = 0; expression[i]; i++) {
        if (expression[i] == '(' || expression[i] == '{' || expression[i] == '[')
            push(&stack, expression[i]);
        if (expression[i] == ')' || expression[i] == '}' || expression[i] == ']') {
            if (isEmpty(&stack))
                return 0;
            char top = pop(&stack);
            if (!isMatchingPair(top, expression[i]))
                return 0;
        }
    }
    return isEmpty(&stack);
}

int main() {
    char expression[MAX_SIZE];

    printf("Enter an expression: ");
    scanf("%s", expression);

    if (isBalanced(expression))
        printf("Balancedn");
    else
        printf("Not Balancedn");

    return 0;
}
📤 Output:
Input: {([])}
Output: Balanced

Input: ([)]
Output: Not Balanced

Input: ((
Output: Not Balanced

Input: ))
Output: Not Balanced

Input: abc
Output: Balanced

Input: {a[b(c)d]e}
Output: Balanced

Input: {a[b(c)d]e
Output: Not Balanced

💻 Check for Balanced Parentheses
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX_SIZE 100

struct Stack {
    int top;
    char items[MAX_SIZE];
};

void initialize(struct Stack *s) {
    s->top = -1;
}

int isEmpty(struct Stack *s) {
    return (s->top == -1);
}

int isFull(struct Stack *s) {
    return (s->top == MAX_SIZE - 1);
}

void push(struct Stack *s, char c) {
    if (isFull(s)) {
        printf("Stack Overflow n");
        return;
    }
    s->items[++(s->top)] = c;
}

char pop(struct Stack *s) {
    if (isEmpty(s)) {
        return '0';
    }
    return s->items[(s->top)--];
}

int isMatchingPair(char character1, char character2) {
    if (character1 == '(' && character2 == ')')
        return 1;
    else if (character1 == '{' && character2 == '}')
        return 1;
    else if (character1 == '[' && character2 == ']')
        return 1;
    else
        return 0;
}

int isBalanced(char exp[]) {
    struct Stack s;
    initialize(&s);

    for (int i = 0; exp[i]; i++) {
        if (exp[i] == '(' || exp[i] == '{' || exp[i] == '[')
            push(&s, exp[i]);

        if (exp[i] == ')' || exp[i] == '}' || exp[i] == ']') {
            if (isEmpty(&s))
                return 0;

            char top = pop(&s);
            if (!isMatchingPair(top, exp[i]))
                return 0;
        }
    }

    return (isEmpty(&s) ? 1 : 0);
}

int main() {
    char exp[MAX_SIZE];

    printf("Enter an expression: ");
    scanf("%s", exp);

    if (isBalanced(exp))
        printf("Balanced n");
    else
        printf("Not Balanced n");

    return 0;
}
📤 Output:
Input: {([])}
Output: Balanced

Input: ([)]
Output: Not Balanced

Input: ((
Output: Not Balanced

Input: ))
Output: Not Balanced

Input: abc
Output: Balanced

Input: {[()]}
Output: Balanced

💻 Implement Stack Using Linked List
#include <stdio.h>
#include <stdlib.h>

struct Node {
  int data;
  struct Node *next;
};

struct Node *top = NULL;

void push(int value) {
  struct Node *newNode = (struct Node *)malloc(sizeof(struct Node));
  if (newNode == NULL) {
    printf("Stack Overflown");
    return;
  }
  newNode->data = value;
  newNode->next = top;
  top = newNode;
  printf("%d pushed to stackn", value);
}

void pop() {
  if (top == NULL) {
    printf("Stack Underflown");
    return;
  }
  struct Node *temp = top;
  top = top->next;
  printf("%d popped from stackn", temp->data);
  free(temp);
}

void peek() {
  if (top == NULL) {
    printf("Stack is emptyn");
    return;
  }
  printf("Top element is %dn", top->data);
}

int isEmpty() {
  return top == NULL;
}

int main() {
  int choice, value;

  while (1) {
    printf("nStack Operations:n");
    printf("1. Pushn");
    printf("2. Popn");
    printf("3. Peekn");
    printf("4. IsEmptyn");
    printf("5. Exitn");
    printf("Enter your choice: ");
    scanf("%d", &choice);

    switch (choice) {
      case 1:
        printf("Enter value to push: ");
        scanf("%d", &value);
        push(value);
        break;
      case 2:
        pop();
        break;
      case 3:
        peek();
        break;
      case 4:
        if (isEmpty())
          printf("Stack is emptyn");
        else
          printf("Stack is not emptyn");
        break;
      case 5:
        exit(0);
      default:
        printf("Invalid choicen");
    }
  }

  return 0;
}
📤 Output:
Stack Operations:
1. Push
2. Pop
3. Peek
4. IsEmpty
5. Exit
Enter your choice: 1
Input: 10
Enter value to push: 10
Output: 10 pushed to stack

Stack Operations:
1. Push
2. Pop
3. Peek
4. IsEmpty
5. Exit
Enter your choice: 1
Input: 20
Enter value to push: 20
Output: 20 pushed to stack

Stack Operations:
1. Push
2. Pop
3. Peek
4. IsEmpty
5. Exit
Enter your choice: 3
Output: Top element is 20

Stack Operations:
1. Push
2. Pop
3. Peek
4. IsEmpty
5. Exit
Enter your choice: 2
Output: 20 popped from stack

Stack Operations:
1. Push
2. Pop
3. Peek
4. IsEmpty
5. Exit
Enter your choice: 4
Output: Stack is not empty

Stack Operations:
1. Push
2. Pop
3. Peek
4. IsEmpty
5. Exit
Enter your choice: 2
Output: 10 popped from stack

Stack Operations:
1. Push
2. Pop
3. Peek
4. IsEmpty
5. Exit
Enter your choice: 4
Output: Stack is empty

Stack Operations:
1. Push
2. Pop
3. Peek
4. IsEmpty
5. Exit
Enter your choice: 2
Output: Stack Underflow

Stack Operations:
1. Push
2. Pop
3. Peek
4. IsEmpty
5. Exit
Enter your choice: 5

💻 Implement Stack Using Array
#include <stdio.h>
#include <stdlib.h>

#define MAX_SIZE 100

int stack[MAX_SIZE];
int top = -1;

void push(int value) {
  if (top >= MAX_SIZE - 1) {
    printf("Stack Overflown");
    return;
  }
  top++;
  stack[top] = value;
  printf("%d pushed to stackn", value);
}

void pop() {
  if (top == -1) {
    printf("Stack Underflown");
    return;
  }
  printf("%d popped from stackn", stack[top]);
  top--;
}

void peek() {
  if (top == -1) {
    printf("Stack is emptyn");
    return;
  }
  printf("Top element is %dn", stack[top]);
}

int isEmpty() {
  return top == -1;
}

int main() {
  int choice, value;

  while (1) {
    printf("nStack Operations:n");
    printf("1. Pushn");
    printf("2. Popn");
    printf("3. Peekn");
    printf("4. IsEmptyn");
    printf("5. Exitn");
    printf("Enter your choice: ");
    scanf("%d", &choice);

    switch (choice) {
      case 1:
        printf("Enter value to push: ");
        scanf("%d", &value);
        push(value);
        break;
      case 2:
        pop();
        break;
      case 3:
        peek();
        break;
      case 4:
        if (isEmpty()) {
          printf("Stack is emptyn");
        } else {
          printf("Stack is not emptyn");
        }
        break;
      case 5:
        exit(0);
      default:
        printf("Invalid choicen");
    }
  }

  return 0;
}
📤 Output:
Stack Operations:
1. Push
2. Pop
3. Peek
4. IsEmpty
5. Exit
Enter your choice: Input: 1
Enter value to push: Input: 10
10 pushed to stack

Stack Operations:
1. Push
2. Pop
3. Peek
4. IsEmpty
5. Exit
Enter your choice: Input: 1
Enter value to push: Input: 20
20 pushed to stack

Stack Operations:
1. Push
2. Pop
3. Peek
4. IsEmpty
5. Exit
Enter your choice: Input: 3
Top element is 20

Stack Operations:
1. Push
2. Pop
3. Peek
4. IsEmpty
5. Exit
Enter your choice: Input: 4
Stack is not empty

Stack Operations:
1. Push
2. Pop
3. Peek
4. IsEmpty
5. Exit
Enter your choice: Input: 2
20 popped from stack

Stack Operations:
1. Push
2. Pop
3. Peek
4. IsEmpty
5. Exit
Enter your choice: Input: 2
10 popped from stack

Stack Operations:
1. Push
2. Pop
3. Peek
4. IsEmpty
5. Exit
Enter your choice: Input: 2
Stack Underflow

Stack Operations:
1. Push
2. Pop
3. Peek
4. IsEmpty
5. Exit
Enter your choice: Input: 4
Stack is empty

Stack Operations:
1. Push
2. Pop
3. Peek
4. IsEmpty
5. Exit
Enter your choice: Input: 5