C Programming
C Programming
College
Programming File
C programming
Submitted to: -
Submitted by:- Neha
Roll no.:- 9031999
Sr.no Name of practical Date of practical Signature
#include <math.h>
int main() {
scanf("%f", &principal);
scanf("%f", &rate);
scanf("%f", &time);
return 0;
#include <stdio.h>
int main() {
float temperature;
int choice;
scanf("%d", &choice);
// Input temperature
scanf("%f", &temperature);
switch (choice) {
case 1:
break;
case 2:
break;
default:
printf("Invalid choice\n");
return 0;
}
3. Writer a program to find largest number between three numbers
(if-then else).
#include <stdio.h>
int main() {
} else {
return 0;
}
4. Write a program to concatenate two strings.
#include <stdio.h>
int main() {
scanf("%s", str1);
scanf("%s", str2);
strcat(str1, str2);
return 0;
}
5 .Write a program to check that the input string is palindrome or not.
#include <stdio.h>
#include <string.h>
return 1; // Palindrome
int main() {
char input[100];
if (isPalindrome(input)) {
return 0;
#include <stdlib.h>
int main() {
int a[100];
scanf("%d", &size);
scanf("%d", &element);
scanf("%d", &loc);
loc--;
// Perform insertion
a[i + 1] = a[i];
a[loc] = element;
}
// Input element for deletion
scanf("%d", &n);
// Perform deletion
i = 0;
if (a[i] == n) {
break;
return 0;
}
7. Write a program to implement linear search.
#include <stdio.h>
if (arr[i] == key) {
int main() {
int arr[100];
scanf("%d", &size);
// Input array elements
scanf("%d", &arr[i]);
scanf("%d", &key);
if (position != -1) {
printf("Element %d found at position %d.\n", key, position + 1); // Adding 1 to show position starting from 1
} else {
return 0;
}
8. Write a program to implement binary search.
#include <stdio.h>
if (arr[mid] == key) {
left = mid + 1;
else {
right = mid - 1;
int main() {
int arr[100];
scanf("%d", &size);
scanf("%d", &arr[i]);
scanf("%d", &key);
if (position != -1) {
printf("Element %d found at position %d.\n", key, position + 1); // Adding 1 to show position starting from 1
} else {
return 0;
}
9. Write a program to short the given no. in ascending order using bubble short.
#include <stdio.h>
arr[j + 1] = temp;
int main() {
int arr[100];
int size;
scanf("%d", &size);
scanf("%d", &arr[i]);
}
// Perform Bubble Sort
bubbleSort(arr, size);
return 0;
void addMatrices(int mat1[10][10], int mat2[10][10], int result[10][10], int rows, int cols) { for (int i = 0; i < rows; i++) {
void subtractMatrices(int mat1[10][10], int mat2[10][10], int result[10][10], int rows, int cols) { for (int i = 0; i < rows; i++) {
}
void multiplyMatrices(int mat1[10][10], int mat2[10][10], int result[10][10], int rows1, int cols1, int rows2, int cols2) {
if (cols1 != rows2) {
printf("Multiplication not possible. Number of columns in the first matrix must be equal to the number of rows in the second
matrix.\n");
return;
for (int i = 0; i < rows1; i++) { for (int j = 0; j < cols2; j++) {
result[i][j] = 0;
void displayMatrix(int mat[10][10], int rows, int cols) { for (int i = 0; i < rows; i++) {
printf("\n");
int main() {
printf("Enter the number of rows and columns for the first matrix:\n"); scanf("%d%d", &rows1, &cols1);
printf("Enter elements for the first matrix:\n"); for (int i = 0; i < rows1; i++) {
printf("Enter the number of rows and columns for the second matrix:\n"); scanf("%d%d", &rows2, &cols2);
printf("Enter elements for the second matrix:\n"); for (int i = 0; i < rows2; i++) {
for (int j = 0; j < cols2; j++) { scanf("%d", &mat2[i][j]);
addMatrices(mat1, mat2, result, rows1, cols1); printf("\nSum of Matrices:\n"); displayMatrix(result, rows1, cols1);
subtractMatrices(mat1, mat2, result, rows1, cols1); printf("\nDifference of Matrices:\n"); displayMatrix(result, rows1, cols1);
}
11. Write a program to implement a stack using array.
#include<stdio.h>
void push(void);
void pop(void);
void display(void);
int main() {
top = -1;
scanf("%d", &n);
printf("\n\t ");
do {
scanf("%d", &choice);
switch (choice) {
case 1:
push();
break;
case 2:
pop();
break;
case 3:
display();
break;
case 4:
printf("\n\t EXIT POINT ");
break;
default:
return 0;
void push() {
if (top >= n - 1) {
printf("\n\tSTACK is overflow");
} else {
scanf("%d", &x);
top++;
stack[top] = x;
void pop() {
} else {
top--;
void display() {
if (top >= 0) {
printf("\n The elements in STACK \n");
printf("%d\n", stack[i]);
} else {
}
12. Write a program to implement a stack using linked list.
#include <stdio.h>
#include <stdlib.h>
struct Node {
int data;
};
newNode->data = val;
newNode->next = head;
head = newNode;
void pop() {
if (head == NULL)
printf("Stack is Empty\n");
else {
temp = head;
head = head->next;
free(temp);
void display() {
temp = temp->next;
printf("NULL\n");
int main() {
push(10);
push(20);
push(30);
printf("Linked List\n");
display();
pop();
display();
pop();
display();
return 0;
}
13.Write a program implement a queue using array.
#include <stdio.h>
struct Queue {
int arr[MAX_SIZE];
};
queue->front = -1;
queue->rear = -1;
if (isFull(queue)) {
} else {
if (isEmpty(queue)) {
}
queue->rear = (queue->rear + 1) % MAX_SIZE;
queue->arr[queue->rear] = element;
if (isEmpty(queue)) {
} else {
if (queue->front == queue->rear) {
// If the queue had only one element, reset front and rear
queue->front = -1;
queue->rear = -1;
} else {
if (isEmpty(queue)) {
printf("Queue is empty.\n");
} else {
int i = queue->front;
do {
printf("\n");
int main() {
initializeQueue(&queue);
enqueue(&queue, 10);
enqueue(&queue, 20);
enqueue(&queue, 30);
displayQueue(&queue);
dequeue(&queue);
displayQueue(&queue);
dequeue(&queue);
displayQueue(&queue);
return 0;
}
14. Write a program to implement a circular queue using array.
#include <stdio.h>
#define MAX_SIZE 5
struct CircularQueue {
int arr[MAX_SIZE];
};
cq->front = -1;
cq->rear = -1;
if (isFull(cq)) {
} else {
if (isEmpty(cq)) {
}
cq->rear = (cq->rear + 1) % MAX_SIZE;
cq->arr[cq->rear] = element;
if (isEmpty(cq)) {
} else {
if (cq->front == cq->rear) {
// If the queue had only one element, reset front and rear
cq->front = -1;
cq->rear = -1;
} else {
if (isEmpty(cq)) {
} else {
int i = cq->front;
do {
printf("\n");
int main() {
initializeCircularQueue(&cq);
enqueue(&cq, 10);
enqueue(&cq, 20);
enqueue(&cq, 30);
displayCircularQueue(&cq);
dequeue(&cq);
displayCircularQueue(&cq);
enqueue(&cq, 40);
enqueue(&cq, 50);
enqueue(&cq, 60);
displayCircularQueue(&cq);
dequeue(&cq);
return 0;
}
15. Write a program to implement a simple linked list
#include <stdio.h>
#include <stdlib.h>
struct Node {
int data;
};
struct Node* insertAtBeginning(struct Node* head, int value) { struct Node* newNode = createNode(value);
void displayList(struct Node* head) { struct Node* current = head; printf("Linked List: ");
while (current != NULL) { printf("%d -> ", current->data); current = current->next;
printf("NULL\n");
void freeList(struct Node* head) { struct Node* current = head; while (current != NULL) {
int main() {
freeList(head); return 0;
#include <stdlib.h>
struct TreeNode {
int data;
};
newNode->data = value;
newNode->left = NULL;
newNode->right = NULL;
return newNode;
if (root != NULL) {
inOrderTraversal(root->left);
inOrderTraversal(root->right);
if (root != NULL) {
preOrderTraversal(root->left);
preOrderTraversal(root->right);
if (root != NULL) {
postOrderTraversal(root->left);
postOrderTraversal(root->right);
int main() {
root->left = createNode(2);
root->right = createNode(3);
root->left->left = createNode(4);
root->left->right = createNode(5);
root->right->left = createNode(6);
root->right->right = createNode(7);
inOrderTraversal(root);
printf("\n");
preOrderTraversal(root);
printf("\n");
postOrderTraversal(root);
printf("\n");
return 0;