PF LAB2
PF LAB2
PF LAB2
REG SP24-BCS-200-2E
DATE 1-JANUARY-2025
PROGRAM 1:
#include<stdio.h>
if (number % i == 0) return 0;
return 1;
int main() {
int num;
scanf("%d", &num);
if (prime(num))
else
PROGRAM 2:
#include <stdio.h>
int sum = 0;
sum += arr[i];
return sum;
int main() {
int size;
scanf("%d", &size);
int arr[size];
scanf("%d", &arr[i]);
}
printf("The sum of the array elements is: %d\n", arraySum(arr, size));
return 0;
PROGRAM 3:
#include <stdio.h>
target[j][i] = source[i][j];
int main() {
int matrix[4][5] = {
{1, 2, 3, 4, 5},
{6, 7, 8, 9, 10},
};
int transposed[5][4];
transposeMatrix(rows, cols, matrix, transposed);
printf("Original Matrix:\n");
printf("\n");
printf("\nTransposed Matrix:\n");
printf("\n");
return 0;
PROGRAM 4:
#include<stdio.h>
int main() {
int matrix[5][5];
int largest;
scanf("%d", &matrix[i][j]);
largest = matrix[0][0];
largest = matrix[i][j];
return 0;
PROGRAM 5:
#include <stdio.h>
#define SEATS 50
void displayMenu() {
else
int main() {
while (1) {
displayMenu();
scanf("%d", &choice);
if (choice == 1) {
assignedSeat = -1;
if (seats[i] == 0) {
seats[i] = 1;
assignedSeat = i + 1;
break;
if (assignedSeat == -1) {
printf("First Class is full. Would you like Economy? (1 for Yes, 0 for No): ");
int response;
scanf("%d", &response);
if (response == 1) choice = 2;
else {
continue;
} else {
printBoardingPass(assignedSeat);
continue;
if (choice == 2) {
assignedSeat = -1;
for (int i = 20; i < SEATS; i++) {
if (seats[i] == 0) {
seats[i] = 1;
assignedSeat = i + 1;
break;
if (assignedSeat == -1) {
printf("Economy is full. Would you like First Class? (1 for Yes, 0 for No): ");
int response;
scanf("%d", &response);
if (response == 1) choice = 1;
else {
continue;
} else {
printBoardingPass(assignedSeat);
continue;
}
return 0;
PROGRAM 6:
#include <stdio.h>
int daysInMonth[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
char *months[] = {"January", "February", "March", "April", "May", "June", "July", "August",
"September", "October", "November", "December"};
daysInMonth[1] = 29;
y -= m < 3;
printf(" ");
printf("%5d", i);
if ((i + startingDay) % 7 == 0) {
printf("\n");
printf("\n");
int main() {
scanf("%d", &month);
scanf("%d", &year);
printf("Invalid input!\n");
return 1;
}
printCalendar(month, year);
return 0;
PROGRAM 7:
#include <stdio.h>
struct Transaction {
int division;
int product;
int quantity;
float costPerItem;
};
inventory[t.division][t.product] += t.quantity;
float totalValue = 0;
}
}
return totalValue;
int main() {
float cost[3][4] = {
};
struct Transaction t;
scanf("%d", &t.division);
scanf("%d", &t.product);
printf("Quantity: ");
scanf("%d", &t.quantity);
scanf("%f", &t.costPerItem);
updateInventory(inventory, t);
printf("\nUpdated Inventory:\n");
printf("\n");
return 0;
PROGRAM 8:
#include <stdio.h>
#include <string.h>
struct Student {
char name[50];
int roll;
float marks;
};
int main() {
struct Student students[10];
printf("Name: ");
scanf("%d", &students[i].roll);
printf("Marks: ");
scanf("%f", &students[i].marks);
printf("\nDetails of Students:\n");
return 0;
THE END.