Professional Documents
Culture Documents
a) program:
#include <stdio.h>
int main() {
// Declare a variable of type struct Student
struct Student student;
return 0;
}
o/p:
Enter student name: John Doe
Enter register number: 12345
Enter age: 20
Enter marks for subject 1: 78.5
Enter marks for subject 2: 92.0
Enter marks for subject 3: 85.5
Student Details:
Name: John
Register Number: 12345
Age: 20
Mark 1: 78.50
Mark 2: 92.00
Mark 3: 85.50
11.b) program
#include <stdio.h>
int main() {
int arr[] = {2, 3, 4, 10, 40};
int n = sizeof(arr) / sizeof(arr[0]);
int x = 10;
if (result == -1)
printf("Element is not present in array\n");
else
printf("Element is present at index %d\n", result);
return 0;
}
o/p:
Element is present at index 3
12.a) program:
#include <stdio.h>
int main() {
FILE *file;
char filename[100];
char ch;
if (parent->left != NULL) {
printf("Left child already exists. Cannot insert.\n");
return;
}
parent->left = createNode(data);
}
if (parent->right != NULL) {
printf("Right child already exists. Cannot insert.\n");
return;
}
parent->right = createNode(data);
}
int main() {
// Create the root node
struct TreeNode* root = createNode(1);
return 0;
}
o/p:
In-order traversal of the binary tree: 4 2 5 1 3
13.a) program:
#include <stdio.h>
int main() {
float length, width;
// Get user input for length and width
printf("Enter the length of the rectangle: ");
scanf("%f", &length);
return 0;
}
o/p:
Enter the length of the rectangle: 5.5
Enter the width of the rectangle: 3.2
Area of the rectangle: 17.60
Perimeter of the rectangle: 17.40
13.b)program:
#include <stdio.h>
#include <stdlib.h>
if (queue->front == NULL)
queue->rear = NULL;
free(temp);
return match;
}
// Function to display the FIFA schedule
void displaySchedule(struct Queue* scheduleQueue, int numTeams) {
while (scheduleQueue->front != NULL) {
struct Match match = dequeue(scheduleQueue);
printf("Match: Team %d vs Team %d\n", match.team1, match.team2);
}
}
int main() {
int numTeams;
14.a)program:
#include <stdio.h>
while (number != 0) {
sum += number % 10; // Add the last digit to the sum
number /= 10; // Remove the last digit
}
return sum;
}
int main() {
int num;
return 0;
}
o/p:
Enter a number: 12345
Sum of digits of 12345 is: 15
14.b) program:
#include <stdio.h>
#include <stdlib.h>
return root;
}
int main() {
struct TreeNode* root = NULL;
return 0;
}
o/p:
In-order traversal of the BST: 20 30 40 50 60 70 80
Minimum value in the BST: 20
Maximum value in the BST: 80
15.a)program:
#include <stdio.h>
int main() {
FILE *file;
char data[100];
return 0;
}
o/p:
Enter data to write into file: This is a sample text.
Data written to file1.txt successfully.
15.b)program:
#include <stdio.h>
#include <stdlib.h>
return root;
}
// Node with two children: Get the inorder successor (smallest in the right subtree)
struct TreeNode* temp = findMin(root->right);
return NULL;
}
int main() {
struct TreeNode* root = NULL;
// Insert keys into the BST
root = insert(root, 50);
insert(root, 30);
insert(root, 20);
insert(root, 40);
insert(root, 70);
insert(root, 60);
insert(root, 80);
return 0;
}
o/p:
In-order traversal of the original BST: 20 30 40 50 60 70 80
In-order traversal after deleting node with key 20: 30 40 50 60 70 80
In-order traversal of the empty BST: