Program 1:
#include <stdio.h>
int main() {
int BuildingsRoomsCapacity[3][5];
int i,j;
printf("Enter capacities for each room in each building:\n");
for (i=0;i<3;i++) {
for (j=0;j<5;j++) {
printf("Building %d Room %d: ",i+1,j+1);
scanf("%d",&BuildingsRoomsCapacity[i][j]);
}
}
int maxCapacity=BuildingsRoomsCapacity[0][0];
int maxBuilding=0, maxRoom=0;
for (i=0;i<3;i++) {
for (j=0;j<5;j++) {
if (BuildingsRoomsCapacity[i][j]>maxCapacity) {
maxCapacity=BuildingsRoomsCapacity[i][j];
maxBuilding=i;
maxRoom=j;
}
}
}
printf("Room with maximum capacity is in Building %d, Room %d with a capacity of %d\n",
maxBuilding + 1, maxRoom + 1, maxCapacity);
printf("Capacities of each room in the 2nd building in reverse order:\n");
for (j=4;j>=0;j--) {
printf("Room %d: %d\n",j+1, BuildingsRoomsCapacity[1][j]);
}
printf("Building Nos with the pattern (21, 23, 25, 27, 29):\n");
for (i=0;i<3;i++) {
for (j=0;j<5;j++) {
printf("%d ",BuildingsRoomsCapacity[i][j]);
}
printf("\n");
}
int V;
printf("Enter the number of students: ");
scanf("%d",&V);
int found = 0;
for (i=0;i<3&&!found;i++) {
for (j=0;j<5&&!found;j++) {
if(BuildingsRoomsCapacity[i][j]>=V) {
printf("Room that can accommodate %d students is in Building %d, Room %d\
n",V,i+1,j+1);
found=1;
}
}
}
if (!found) {
printf("No room can accommodate %d students\n", V);
}
printf("Three consecutive rooms with odd capacities:\n");
found = 0;
for (i=0;i<3&&!found;i++) {
for (j=0;j<3&&!found;j++) {
if(BuildingsRoomsCapacity[i][j]%2!=0&&BuildingsRoomsCapacity[i][j+1]%2!
=0&&BuildingsRoomsCapacity[i][j+2]%2!=0) {
printf("Building %d, Room %d, Room %d, Room %d\n", i + 1, j + 1, j + 2, j + 3);
found =1;
}
}
}
if (!found) {
printf("No three consecutive rooms with odd capacities found\n");
}
for (i=0;i<3;i++) {
BuildingsRoomsCapacity[i][4]++;
}
printf("Values of BuildingsRoomsCapacity array:\n");
for (i=0;i<3;i++) {
for (=0;j<5;j++) {
printf("%d ",BuildingsRoomsCapacity[i][j]);
}
printf("\n");
}
return 0;
}
Program 2:
#include <stdio.h>
void InputOneTeamRuns(int runs[20][6]) {
for (int i = 0; i < 20; i++) {
printf("Enter runs for over %d: ", i + 1);
for (int j = 0; j < 6; j++) {
scanf("%d", &runs[i][j]);
}
}
}
int CalculateTotalRuns(int runs[20][6]) {
int total = 0;
for (int i = 0; i < 20; i++) {
for (int j = 0; j < 6; j++) {
total += runs[i][j];
}
}
return total;
}
void DisplayTheWinnerTeamName(int team1_runs, int team2_runs) {
if (team1_runs > team2_runs) {
printf("Team-1 is the winner with %d runs.\n", team1_runs);
} else if (team2_runs > team1_runs) {
printf("Team-2 is the winner with %d runs.\n", team2_runs);
} else {
printf("The match is a tie with both teams scoring %d runs.\n", team1_runs);
}
}
void DisplayTheOverNumber(int runs[20][6]) {
for (int i = 0; i < 20; i++) {
if (runs[i][0] == 1 && runs[i][1] == 0 && runs[i][2] == 0 && runs[i][3] == 0 && runs[i]
[4] == 0 && runs[i][5] == 1) {
printf("Pattern (1-0-0-0-0-1) found in over %d\n", i + 1);
}
}
}
void CountandDisplay(int runs[20][6]) {
int count = 0;
for (int i = 0; i < 20; i++) {
int first_half_sum = runs[i][0] + runs[i][1] + runs[i][2];
int second_half_sum = runs[i][3] + runs[i][4] + runs[i][5];
if (first_half_sum > second_half_sum) {
count++;
}
}
printf("Number of overs where sum of runs on first three balls is greater than the last three
balls: %d\n", count);
}
void OutputOneTeamArray(int runs[20][6]) {
for (int i = 0; i < 20; i++) {
for (int j = 0; j < 6; j++) {
printf("%d ", runs[i][j]);
}
printf("\n");
}
}
void AddBothArraysValuesAndDisplay(int team1[20][6], int team2[20][6]) {
int SUM[20][6];
for (int i = 0; i < 20; i++) {
for (int j = 0; j < 6; j++) {
SUM[i][j] = team1[i][j] + team2[i][j];
}
}
printf("Sum of both teams' runs:\n");
for (int i = 0; i < 20; i++) {
for (int j = 0; j < 6; j++) {
printf("%d ", SUM[i][j]);
}
printf("\n");
}
}
void OutputBothTeamRuns(int team1[20][6], int team2[20][6]) {
printf("Team 1 runs:\n");
OutputOneTeamArray(team1);
printf("Team 2 runs:\n");
OutputOneTeamArray(team2);
}
int main() {
int Team_1_Runs[20][6];
int Team_2_Runs[20][6];
printf("Input runs for Team 1:\n");
InputOneTeamRuns(Team_1_Runs);
printf("Input runs for Team 2:\n");
InputOneTeamRuns(Team_2_Runs);
int total_runs_team1 = CalculateTotalRuns(Team_1_Runs);
int total_runs_team2 = CalculateTotalRuns(Team_2_Runs);
DisplayTheWinnerTeamName(total_runs_team1, total_runs_team2);
printf("Checking for pattern (1-0-0-0-0-1) in Team 1:\n");
DisplayTheOverNumber(Team_1_Runs);
printf("Checking for pattern (1-0-0-0-0-1) in Team 2:\n");
DisplayTheOverNumber(Team_2_Runs);
printf("Counting overs where the sum of the first three balls is greater than the last three for
Team 1:\n");
CountandDisplay(Team_1_Runs);
printf("Counting overs where the sum of the first three balls is greater than the last three for
Team 2:\n");
CountandDisplay(Team_2_Runs);
printf("Outputting runs for Team 1:\n");
OutputOneTeamArray(Team_1_Runs);
printf("Outputting runs for Team 2:\n");
OutputOneTeamArray(Team_2_Runs);
AddBothArraysValuesAndDisplay(Team_1_Runs, Team_2_Runs);
OutputBothTeamRuns(Team_1_Runs, Team_2_Runs);
return 0;
}
Program 3:
#include <stdio.h>
struct VaccinationCenter {
int VaccinationCenterID;
int VaccineIDs[5];
int VaccineCount[5];
int ChildAgeLimitForEachVaccine[5];
};
int main() {
struct VaccinationCenter VC1;
printf("Enter Vaccination Center ID: ");
scanf("%d", &[Link]);
printf("Enter Vaccine IDs (5 values): ");
for (int i = 0; i < 5; i++) {
scanf("%d", &[Link][i]);
}
printf("Enter Vaccine Counts: ");
for (int i = 0; i < 5; i++) {
scanf("%d", &[Link][i]);
}
printf("Enter Child Age Limits for each Vaccine: ");
for (int i = 0; i < 5; i++) {
scanf("%d", &[Link][i]);
}
for (int i = 0; i < 5; i++) {
if ([Link][i] == 1) {
printf("The first VaccineID that can be given to a child aged 1 is: %d\n",
[Link][i]);
break;
}
}
for (int i = 4; i >= 0; i--) {
if ([Link][i] == 2) {
printf("The last VaccineID that can be given to a child aged 2 is: %d\n",
[Link][i]);
break;
}
}
int maxVaccines = 0, maxAge = 0;
for (int i = 0; i < 5; i++) {
if ([Link][i] > maxVaccines) {
maxVaccines = [Link][i];
maxAge = [Link][i];
}
}
printf("The age at which maximum vaccines are given is: %d\n", maxAge);
int isAscending = 1;
for (int i = 0; i < 4; i++) {
if ([Link][i] > [Link][i + 1]) {
isAscending = 0;
break;
}
}
printf("Are Vaccine IDs in ascending order? %s\n", isAscending ? "Yes" : "No");
printf("Vaccine IDs not given to any child so far: ");
for (int i = 0; i < 5; i++) {
if ([Link][i] == 0) {
printf("%d ", [Link][i]);
}
}
printf("\n");
printf("Age limits for all vaccines: ");
for (int i = 0; i < 5; i++) {
printf("%d ", [Link][i]);
}
printf("\n");
int sum = 0;
for (int i = 0; i < 5; i++) {
if ([Link][i] == 1) {
sum += [Link][i];
}
}
printf("Sum of VaccineCount for vaccines given to 1-year-old children: %d\n", sum);
int *P1 = &[Link][0];
int *P2 = &[Link][4];
printf("The first and last values of VaccineCount are: %s\n", (*P1 == *P2) ? "SAME" :
"DIFFERENT");
return 0;
}
Program 4:
#include <stdio.h>
struct Restaurant {
int RestaurantID;
int DishesIDs[5];
float DishesPrices[5];
float TotalEarnings;
};
void Input(struct Restaurant R[2]) {
for (int i = 0; i < 2; i++) {
printf("Enter details for Restaurant %d\n", i + 1);
printf("Enter Restaurant ID: ");
scanf("%d", &R[i].RestaurantID);
printf("Enter 5 Dish IDs: ");
for (int j = 0; j < 5; j++) {
scanf("%d", &R[i].DishesIDs[j]);
}
printf("Enter prices for 5 Dishes: ");
for (int j = 0; j < 5; j++) {
scanf("%f", &R[i].DishesPrices[j]);
}
R[i].TotalEarnings = 0.0;
}
}
void ShowMenu(struct Restaurant R[2]) {
int index;
printf("Enter the index of the Restaurant (0 or 1): ");
scanf("%d", &index);
printf("Menu for Restaurant %d:\n", R[index].RestaurantID);
for (int i = 0; i < 5; i++) {
printf("Dish ID: %d, Price: %.2f\n", R[index].DishesIDs[i], R[index].DishesPrices[i]);
}
}
void DisplayMostExpensiveDish(struct Restaurant R[2]) {
int maxIndex = 0, maxRestaurant = 0;
float maxPrice = R[0].DishesPrices[0];
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 5; j++) {
if (R[i].DishesPrices[j] > maxPrice) {
maxPrice = R[i].DishesPrices[j];
maxIndex = j;
maxRestaurant = i;
}
}
}
printf("The most expensive dish is in Restaurant %d: Dish ID: %d, Price: %.2f\n",
R[maxRestaurant].RestaurantID, R[maxRestaurant].DishesIDs[maxIndex], maxPrice);
}
void DisplayIDofDish(struct Restaurant R[2]) {
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 5; j++) {
if (R[0].DishesIDs[i] == R[1].DishesIDs[j]) {
printf("Dish ID %d exists in both restaurants\n", R[0].DishesIDs[i]);
return;
}
}
}
printf("No common dish ID found in both restaurants\n");
}
void OrderDish(struct Restaurant R[2]) {
int index, dishID;
printf("Enter the index of the Restaurant (0 or 1): ");
scanf("%d", &index);
printf("Enter the Dish ID to order: ");
scanf("%d", &dishID);
for (int i = 0; i < 5; i++) {
if (R[index].DishesIDs[i] == dishID) {
R[index].TotalEarnings += R[index].DishesPrices[i];
printf("Order placed. Total earnings of Restaurant %d updated to %.2f\n",
R[index].RestaurantID, R[index].TotalEarnings);
return;
}
}
printf("Dish ID not found in the selected restaurant\n");
}
void UpdatePriceofDish(struct Restaurant R[2]) {
int index, dishID;
float newPrice;
printf("Enter the index of the Restaurant (0 or 1): ");
scanf("%d", &index);
printf("Enter the Dish ID to update the price: ");
scanf("%d", &dishID);
printf("Enter the new price: ");
scanf("%f", &newPrice);
for (int i = 0; i < 5; i++) {
if (R[index].DishesIDs[i] == dishID) {
R[index].DishesPrices[i] = newPrice;
printf("Price of Dish ID %d in Restaurant %d updated to %.2f\n",
dishID, R[index].RestaurantID, newPrice);
return;
}
}
printf("Dish ID not found in the selected restaurant\n");
}
int main() {
struct Restaurant R[2];
Input(R);
ShowMenu(R);
DisplayMostExpensiveDish(R);
DisplayIDofDish(R);
OrderDish(R);
UpdatePriceofDish(R);
return 0;
}
Program 5:
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main() {
char Sentence1[100];
char Sentence2[100];
printf("Enter the first sentence: ");
fgets(Sentence1, sizeof(Sentence1), stdin);
Sentence1[strcspn(Sentence1, "\n")] = '\0';
printf("Enter the second sentence: ");
fgets(Sentence2, sizeof(Sentence2), stdin);
Sentence2[strcspn(Sentence2, "\n")] = '\0';
int isPalindrome(char sentence[]) {
int left = 0;
int right = strlen(sentence) - 1;
while (left < right) {
while (left < right && !isalnum(sentence[left])) left++;
while (left < right && !isalnum(sentence[right])) right--;
if (tolower(sentence[left]) != tolower(sentence[right])) {
return 0;
left++;
right--;
return 1;
if (isPalindrome(Sentence1)) {
printf("Sentence1 is a Palindrome\n");
} else {
printf("Sentence1 is not a Palindrome\n");
if (isPalindrome(Sentence2)) {
printf("Sentence2 is a Palindrome\n");
} else {
printf("Sentence2 is not a Palindrome\n");
void displayCharactersAfterSpaces(char sentence[]) {
printf("Characters after spaces in the sentence: ");
for (int i = 0; i < strlen(sentence) - 1; i++) {
if (sentence[i] == ' ' && sentence[i + 1] != ' ') {
printf("%c ", sentence[i + 1]);
printf("\n");
displayCharactersAfterSpaces(Sentence1);
displayCharactersAfterSpaces(Sentence2);
return 0;
THE END