pf ass 2
pf ass 2
SYED NADEEM
RIZVI
REGISTRATION NO
SP24-BCS-192
ASSIGNMENT
2
31 DECEMBER 2024
SYED NADEEM
QUESTIONS
SYED NADEEM
QUESTIONS
Develop a program that receives the month and year from the
06 keyboard as integers and prints the calendar in the following
format.
SYED NADEEM
QUESTIONS
SYED NADEEM
ANSWERS 1
#include <stdio.h>
int isPrime(int n) {
if (n <= 1) {
return 0;
}
int main() {
printf("SYED NADEEM BCS 192\n");
int n;
printf("ENTER THE NUMBER : ");
scanf("%d", &n);
int result;
result = isPrime(n);
printf("%d\n", result);
return 0;
}
ANSWERS 2
#include <stdio.h>
int main() {
printf("SYED NADEEM BCS 192\n");
int arr[3][3];
int i, j;
printf("ENTER MATRIX:\n");
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
printf("Enter element [%d][%d]: ", i, j);
scanf("%d", &arr[i][j]);
}
}
printf("\nOriginal Matrix:\n");
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
printf("%4d", arr[i][j]);
}
printf("\n");
}
printf("\nTransposed Matrix:\n");
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
printf("%4d", arr[j][i]);
}
printf("\n");
}
return 0;
}
ANSWERS 3
#include <stdio.h>
void transposeMatrix(int rows, int cols, int m[rows][cols], int
n[cols][rows]) {
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
n[j][i] = m[i][j];
}
}
}
int main() {
printf("SYED NADEEM BCS 192\n");
int rows, cols;
int matrix[rows][cols];
int transposed[cols][rows];
printf("Enter matrix elements:\n");
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
scanf("%d", &matrix[i][j]);
}
}
printf("Transposed Matrix:\n");
for (int i = 0; i < cols; i++) {
for (int j = 0; j < rows; j++) {
printf("%d ", transposed[i][j]);
}
printf("\n");
}
return 0;
}
ANSWERS 4
#include <stdio.h>
int main() {
printf("SYED NADEEM BCS 192\n");
int matrix[5][5] = {
{1, 2, 3, 4, 5},
{6, 7, 8, 9, 10},
{11, 12, 13, 14, 15},
{16, 17, 18, 19, 20},
{21, 22, 23, 24, 25}
};
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#define TOTAL_SEATS 50
#define FIRST_CLASS_CAPACITY 20
switch (choice) {
case 1:
first_class(seats);
break;
case 2:
economy_class(seats);
break;
case 3:
printf("Exiting the program.\n");
exit(0);
default:
printf("Invalid choice. Please enter 1, 2, or 3.\n");
break;
}
}
return 0;
ANSWERS 5
#include <stdio.h>
void printCalendar(int month, int year) {
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"};
int main() {
printf("SYED NADEEM BCS 192\n");
int month, year;
printf("Enter month (1-12): ");
if (scanf("%d", &month) != 1) {
printf("Invalid month input. Please enter a number.\n");
return 1;
}
printf("Enter year: ");
if (scanf("%d", &year) != 1) {
printf("Invalid year input. Please enter a number.\n");
return 1;
}
printCalendar(month, year);
return 0;
}
ANSWERS 7
#include <stdio.h>
#define DIVISIONS 3
#define PRODUCTS 4
typedef struct {
int divisionId, productId, quantity, supplierId;
float costPerItem;
} Transaction;
void updateInventory(int inv[DIVISIONS][PRODUCTS], Transaction t) {
if (t.divisionId < 0 || t.divisionId >= DIVISIONS || t.productId < 0 || t.productId >=
PRODUCTS) {
printf("Invalid transaction.\n");
return;
}
inv[t.divisionId][t.productId] += t.quantity;
}
int main() {
printf("SYED NADEEM BCS 192\n");
int inv[DIVISIONS][PRODUCTS] = {0}, numTrans;
Transaction trans[numTrans];
for (int i = 0; i < numTrans; i++) {
printf("\nTransaction %d:\n", i + 1);
printf("Division (0-%d): ", DIVISIONS - 1);
if (scanf("%d", &trans[i].divisionId) != 1) return 1;
printf("Product (0-%d): ", PRODUCTS - 1);
if (scanf("%d", &trans[i].productId) != 1) return 1;
printf("Quantity: ");
if (scanf("%d", &trans[i].quantity) != 1) return 1;
printf("Cost: ");
if (scanf("%f", &trans[i].costPerItem) != 1) return 1;
updateInventory(inv, trans[i]);
}
printf("\nInventory:\n");
for (int i = 0; i < DIVISIONS; i++) {
printf("Div %d: ", i);
for (int j = 0; j < PRODUCTS; j++) {
printf("%d ", inv[i][j]);
ANSWERS 8
#include <stdio.h>
struct student
{
int roll;
char name[50];
float marks;
};
int main()
{
printf("SYED NADEEM BCS 192\n");
int i, n;
printf("\nEnter the Total Number Of Student: ");
scanf("%d", &n);
return 0;