Codekata-Report-1736409265770
Codekata-Report-1736409265770
Email: [email protected]
Section: Section-31
)
.in
ac
ty.
rsi
1. Problem: Student Records ManagementObjective:
ive
Write a C program to manage a set of student records using arrays, pointers,
un
structures, and unions. The program should allow storing and displaying information
about each student, including their grades and status.
ias
t
lgo
ga
Specifications:
9@
Structures:
14
80
Please define a structure named Student with these following members:Name (Its an
1
array of characters with a maximum length = 50)id (an integer)grades (an array of five
e1
The union status can either hold:char passFail ('P' for pass, 'F' for fail) if the average is
a
ep
greater than or equal to 50.int gradeCategory (1 for excellent, 2 for good, 3 for
de
average, 4 for poor) based on the average score:Excellent (>= 85)Good (>= 70 and <
a(
grades for each student.void determineStatus(Student *s, int n) - to set the status of
e
Your code should first read an integer n = the number of students.Then, it should read
the name, ID, and the five grades for each student.Calculate the average, determine
the status, and display the details of each student.ExampleInput:2Alice 101 75.0 82.0
90.0 70.0 88.0Bob 102 45.0 55.0 65.0 35.0 60.0
Student: BobID: 102Grades: 45.0, 55.0, 65.0, 35.0, 60.0Average: 52.0Status: Pass/Fail
-P
Completion Status: Completed
Concepts Included:
gu 28 1st semester c programming
Language Used: C
Source Code:
#include <stdio.h>
#include <string.h>
// Define the structure and union
typedef struct {
)
.in
char name[50];
ac
int id;
ty.
float grades[5];
rsi
float average;
ive
union {
un
char passFail;
int gradeCategory;
iast
lgo
} status;
ga
} Student;
9@
}
a
ep
}
de
}
a(
sum += s[i].grades[j];
}
s[i].average = sum / 5; // Calculate the average
}
}
// Function to determine the status of each student
void determineStatus(Student *s, int n) {
for (int i = 0; i < n; i++) {
if (s[i].average >= 85) {
s[i].status.gradeCategory = 1; // Excellent
} else if (s[i].average >= 70) {
s[i].status.gradeCategory = 2; // Good
} else if (s[i].average >= 50) {
s[i].status.passFail = 'P'; // Pass
} else {
s[i].status.passFail = 'F'; // Fail
}
}
}
// Function to display student details
void displayStudents(const Student *s, int n) {
for (int i = 0; i < n; i++) {
printf("Student: %s\n", s[i].name);
printf("ID: %d\n", s[i].id);
printf("Grades: ");
for (int j = 0; j < 5; j++) {
printf("%.1f", s[i].grades[j]);
if (j < 4) printf(", "); // Separate grades with commas
}
)
.in
printf("\nAverage: %.1f\n", s[i].average);
ac
// Display status
ty.
if (s[i].average >= 70) {
rsi
printf("Status: Grade Category - %d\n", s[i].status.gradeCategory);
ive
} else {
un
printf("Status: Pass/Fail - %c\n", s[i].status.passFail);
ias
}
t
lgo
}
}
ga
// Main function
9@
int main() {
14
int n;
80
scanf("%d", &n);
1
e1
Student students[n];
cs
inputStudentData(students, n);
4s
calculateAverage(students, n);
li.2
determineStatus(students, n);
a
displayStudents(students, n);
ep
return 0;
de
}
a(
m
er
Compilation Details:
li V
pa
e
TestCase1:
De
Input:
< hidden >
Expected Output:
< hidden >
Output:
Enter the number of sets of data: Enter integer a: Enter floating-point number b: Enter
operator (+, -, *, /): Enter double precision number c: Invalid operator.
0.00
Compilation Status: Failed
Execution Time:
0.001s
TestCase2:
Input:
< hidden >
Expected Output:
< hidden >
)
.in
Output:
ac
ty.
Enter the number of sets of data: Enter integer a: Enter floating-point number b: Enter
rsi
operator (+, -, *, /): Enter double precision number c: Invalid operator.
ive
0.00
un
ias
Compilation Status: Failed
t
lgo
Execution Time:
ga
9@
0.001s
14
80
1
Read two integers from the user, one of type short and the other of type long
de
long.Calculate and display the following:The sum of the two integers.The difference
a(
between the long long integer and the short integer.The product of the two
m
integers.The result of dividing the long long integer by the short integer (consider
er
sum of a and b.The difference between b and a.The product of a and b.The result of b
pa
range of -32,768 to 32,767.The long long integer b should be within the range of
-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807.The short integer a should
not be zero for the division operation.ExplanationThe program demonstrates the use
of different type modifiers (short and long long) and performs basic arithmetic
operations. It will handle integer overflow cases by leveraging the large range of long
long and provide meaningful outputs.
ExampleInput:510000000000
Language Used: C
Source Code:
#include <stdio.h>
int main() {
short a;
long long b;
scanf("%hd", &a);
scanf("%lld", &b);
)
.in
if (a == 0) {
ac
printf("Error\n");
ty.
return 1;
rsi
}
ive
long long sum = a + b;
un
long long difference = b - a;
ias
long long product = (long long)a * b;
long long division = b / a; t
lgo
printf("Sum: %lld\n", sum);
ga
return 0;
1
e1
}
cs
4s
Compilation Details:
ali.2
ep
TestCase1:
de
a(
Input:
m
er
Expected Output:
e
De
Output:
Sum: 123456789012347
Difference: 123456789012343
Product: 246913578024690
Division: 61728394506172
Expected Output:
< hidden >
Output:
Sum: -100000000000001
Difference: -99999999999999
Product: 100000000000000
Division: 100000000000000
)
.in
ac
Compilation Status: Passed
ty.
rsi
Execution Time:
ive
0.001s
un
ias
t
lgo
3. Problem Statement:You are tasked with writing a program that
ga
The program should analyze the user input to determine if it can fit
1
into any of the predefined C types with their associated ranges and
e1
cs
that control the size and representation of variables. Depending on the input value, it
ep
may fit within certain ranges of these types. Your job is to create a program that takes
de
an integer input and determines the type modifiers it can fit into based on its size.
a(
m
The program must evaluate the number with respect to the ranges for:
er
li V
short intlong intunsigned short intunsigned long intFor example, signed short int can
pa
represent values from -32,768 to 32,767, and unsigned short int can represent values
e
from 0 to 65,535.
De
Output Format:The program should output the types the number can fit into. For each
type, print:Fits in short int (if the number fits)Fits in long int (if the number fits)Fits in
unsigned short int (if the number fits)Fits in unsigned long int (if the number fits)If the
number does not fit into any of these types, print Does not fit in any type.
Sample Input:12345
Sample Output:
Fits in short intFits in long intFits in unsigned short intFits in unsigned long int
Constraints:The number can be as large as a long long int, i.e., in the range of
-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807.
Concepts Included:
gu 28 1st semester c programming
Language Used: C
Source Code:
)
.in
#include <stdio.h>
ac
#include <limits.h>
ty.
rsi
int main() {
ive
long long n;
un
scanf("%lld", &n);
ias
int fits_short = 0, fits_long = 0, fits_unsigned_short = 0, fits_unsigned_long = 0;
if (n >= SHRT_MIN && n <= SHRT_MAX) { t
lgo
printf("Fits in short int\n");
ga
fits_short = 1;
9@
}
14
fits_long = 1;
e1
}
cs
fits_unsigned_short = 1;
a
ep
}
de
fits_unsigned_long = 1;
er
}
li V
Compilation Details:
TestCase1:
Input:
< hidden >
Expected Output:
< hidden >
Output:
Fits in short int
Fits in long int
Fits in unsigned short int
Fits in unsigned long int
)
.in
ac
TestCase2:
ty.
rsi
Input:
ive
un
< hidden >
Output:
80
1
Execution Time:
ep
de
0.002s
a(
m
er
li V
Write a C program that reads a series of values, performs arithmetic calculations, and
De
then outputs the results. The values and operations are defined as follows:
Input:
Integer n which is representing the number of sets of data to process.For each set:An
integer value a.A floating-point number b.A character op representing an arithmetic
operation (+, -, *, /).A double precision number c.Output:
For each set of data, perform the operation specified by op on a and b, and add the
result to c.Output the result as a double-precision floating-point number with two
decimal places.Constraints:
1 <= n <= 1000 <= a <= 10000.0 <= b <= 1000.0op will be one of the characters: +, -,
*, /.c will be a valid double precision number.If the operation is division (/), ensure no
division by zero occurs.
Output:10.7033.2010.00
Explanation:
First Set: 5 + 3.2 + 2.5 = 10.7Second Set: 8 * 4.0 + 1.2 = 33.2Third Set: 10.0 + 0.0 =
10.0 (Division by zero avoided)
Concepts Included:
)
.in
gu 28 1st semester c programming
ac
ty.
rsi
Language Used: C
ive
un
ias
Source Code:
t
lgo
#include <stdio.h>
ga
int main() {
9@
int n;
14
scanf("%d", &n);
80
int a;
e1
float b;
cs
char op;
4s
if (op == '+') {
m
result = a + b + c;
er
result = a - b + c;
pa
result = a * b + c;
if (b != 0.0) {
result = a / b + c;
} else {
result = c; // Division by zero, only add `c`
}
}
// Print the result with two decimal places
printf("%.2lf\n", result);
}
return 0;
}
Compilation Details:
TestCase1:
Input:
< hidden >
Expected Output:
< hidden >
Output:
)
.in
ac
16.00
ty.
101.00
rsi
ive
Compilation Status: Passed
un
ias
Execution Time:
t
lgo
0.002s
ga
9@
TestCase2:
14
80
Input:
1
e1
Expected Output:
li.2
a
ep
Output:
a(
m
10.00
er
li V
Execution Time:
0.001s
)
.in
ac
ty.
Completion Status: Completed
rsi
ive
un
Concepts Included:
gu 28 1st semester c programming
iast
lgo
ga
Language Used: C
9@
14
80
Source Code:
1
e1
#include <stdio.h>
cs
while ((guess * guess - number) > epsilon || (number - guess * guess) > epsilon) {
de
}
m
return guess;
er
}
li V
int main() {
pa
int n;
e
De
scanf("%d", &n);
if (n < 1 || n > 100) {
return 1;
}
float arr[n], sum = 0.0, max, min, mean, stddev = 0.0;
for (int i = 0; i < n; i++) {
scanf("%f", &arr[i]);
sum += arr[i];
if (i == 0) {
max = min = arr[i];
} else {
if (arr[i] > max) max = arr[i];
if (arr[i] < min) min = arr[i];
}
}
mean = sum / n;
for (int i = 0; i < n; i++) {
float diff = arr[i] - mean;
stddev += diff * diff;
}
stddev = custom_sqrt(stddev / n);
printf("Average: %.2f\n", mean);
printf("Maximum: %.2f\n", max);
printf("Minimum: %.2f\n", min);
printf("Standard Deviation: %.2f\n", stddev);
return 0;
}
)
Compilation Details:
.in
ac
ty.
TestCase1:
rsi
ive
Input:
un
ias
< hidden >
t
lgo
Expected Output:
ga
9@
Output:
80
1
e1
Average: 2.00
cs
Maximum: 3.00
4s
Minimum: 1.00
li.2
Execution Time:
m
er
0.001s
li V
epa
TestCase2:
De
Input:
< hidden >
Expected Output:
< hidden >
Output:
Average: 10.00
Maximum: 30.00
Minimum: -10.00
Standard Deviation: 14.14
Compilation Status: Passed
Execution Time:
0.001s
)
.in
Transaction Types and Attributes:Deposit:Amount (float)Account Number
ac
(integer)Withdrawal:Amount (float)Account Number (integer)ATM Location
ty.
(string)Transfer:Amount (float)From Account Number (integer)To Account Number
rsi
(integer)
ive
un
TaskWrite a program that takes user input to fill in the transaction details and then
ias
prints out the transaction information.
t
lgo
InputThis first line will contain a character representing the transaction type:D for
ga
DepositW for WithdrawalT for TransferThe subsequent lines contain the necessary
9@
floating-point number representing the amount.An integer for the account number.A
1
string for the ATM location.For Transfer:A floating-point number representing the
e1
amount.An integer for the from account number.An integer for the to account
cs
number.
4s
li.2
including the transaction type, amount, account numbers, and other relevant details.
de
Sample Input:D5000.0012345
a(
m
numbers are the integers and they will be positive numbers less than 100,000.The
e
De
ATM location string will not exceed 50 characters.Input should be validated to ensure
correct transaction type.
Concepts Included:
gu 28 1st semester c programming
Language Used: C
Source Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef union {
struct {
float amount;
int accountNumber;
} deposit;
)
struct {
.in
float amount;
ac
int accountNumber;
ty.
rsi
char atmLocation[51];
ive
} withdrawal;
un
ias
struct {
float amount; t
lgo
int fromAccountNumber;
ga
int toAccountNumber;
9@
} transfer;
14
} TransactionData;
80
1
typedef struct {
e1
char type;
cs
TransactionData data;
4s
} Transaction;
li.2
a
ep
switch (transaction->type) {
a(
case 'D':
m
break;
e
De
case 'W':
printf("Transaction Type: Withdrawal\n");
printf("Amount: %.2f\n", transaction->data.withdrawal.amount);
printf("Account Number: %d\n", transaction->data.withdrawal.accountNumber);
printf("ATM Location: %s\n", transaction->data.withdrawal.atmLocation);
break;
case 'T':
printf("Transaction Type: Transfer\n");
printf("Amount: %.2f\n", transaction->data.transfer.amount);
printf("From Account Number: %d\n", transaction-
>data.transfer.fromAccountNumber);
printf("To Account Number: %d\n", transaction->data.transfer.toAccountNumber);
break;
default:
printf("Invalid transaction type.\n");
break;
}
}
int main() {
Transaction transaction;
scanf(" %c", &transaction.type);
switch (transaction.type) {
case 'D':
scanf("%f", &transaction.data.deposit.amount);
scanf("%d", &transaction.data.deposit.accountNumber);
break;
case 'W':
)
.in
scanf("%f", &transaction.data.withdrawal.amount);
ac
scanf("%d", &transaction.data.withdrawal.accountNumber);
ty.
scanf(" %[^\n]", transaction.data.withdrawal.atmLocation);
rsi
break;
ive
case 'T':
un
scanf("%f", &transaction.data.transfer.amount);
ias
scanf("%d", &transaction.data.transfer.fromAccountNumber);
t
lgo
scanf("%d", &transaction.data.transfer.toAccountNumber);
break;
ga
default:
9@
return 1;
80
}
1
e1
cs
printTransaction(&transaction);
4s
li.2
return 0;
a
}
ep
de
a(
Compilation Details:
m
er
li V
TestCase1:
pa
e
Input:
De
Expected Output:
< hidden >
Output:
Transaction Type: Withdrawal
Amount: 200.00
Account Number: 67890
ATM Location: Main Street ATM
TestCase2:
Input:
< hidden >
Expected Output:
< hidden >
Output:
)
.in
Transaction Type: Transfer
ac
Amount: 1000.00
ty.
From Account Number: 54321
rsi
To Account Number: 98765
ive
un
Compilation Status: Passed
Execution Time: iast
lgo
ga
0.001s
9@
14
80
manage data using arrays and pointers and perform operations like
4s
li.2
find a specific element.Median Calculation: Calculate the median of the sorted array
er
using pointers.
li V
pa
Input FormatThe first line will contain an integer n, such that 1 <= n <= 100000,
e
De
representing the number of elements in the array.The second line contains n space-
separated integers representing the array elements.The third line contains an integer
x, representing the element to search in the array.
ExampleInput:712 4 5 3 8 7 15
Output:1 3 4 5 7 8 125.003
Explanation:Sorting: The sorted array is [1, 3, 4, 5, 7, 8, 12].Median: The median value
of this sorted array is 5 since it is the middle element.Binary Search: The element 5 is
found at index 3 (0-based index) in the sorted array.
Concepts Included:
gu 28 1st semester c programming
Language Used: C
)
Source Code:
.in
ac
#include <stdio.h>
ty.
rsi
#include <stdlib.h>
ive
void quicksort(int *arr, int low, int high) {
un
if (low < high) {
ias
int pivot = arr[high];
int i = low - 1, j, temp; t
lgo
for (j = low; j < high; j++) {
ga
9@
i++;
1
temp = arr[i];
e1
arr[i] = arr[j];
cs
arr[j] = temp;
4s
}
li.2
}
a
ep
arr[i + 1] = arr[high];
a(
arr[high] = temp;
m
int pi = i + 1;
er
quicksort(arr, pi + 1, high);
pa
}
e
De
}
int binary_search(int *arr, int n, int x) {
int left = 0, right = n - 1, mid;
while (left <= right) {
mid = left + (right - left) / 2;
if (arr[mid] == x)
return mid;
else if (arr[mid] < x)
left = mid + 1;
else
right = mid - 1;
}
return -1;
}
float find_median(int *arr, int n) {
if (n % 2 == 0)
return (arr[n / 2 - 1] + arr[n / 2]) / 2.0;
else
return arr[n / 2];
}
int main() {
int n, x, i;
scanf("%d", &n);
int *arr = (int *)malloc(n * sizeof(int));
for (i = 0; i < n; i++)
scanf("%d", &arr[i]);
scanf("%d", &x);
)
.in
quicksort(arr, 0, n - 1);
ac
for (i = 0; i < n; i++)
ty.
printf("%d ", arr[i]);
rsi
printf("\n");
ive
printf("%.2f\n", find_median(arr, n));
un
printf("%d\n", binary_search(arr, n, x));
ias
free(arr);
t
lgo
return 0;
}
ga
9@
14
Compilation Details:
80
1
e1
TestCase1:
cs
4s
Input:
ali.2
Expected Output:
a(
m
Output:
epa
11345
De
3.00
3
TestCase2:
Input:
< hidden >
Expected Output:
< hidden >
Output:
3 5 7 8 9 10
7.50
3
)
.in
ac
8. Problem StatementWrite a C program to manage student records
ty.
for a class. Each student has a name, roll number, marks in three
rsi
ive
subjects, and their calculated total and average marks. The program
un
should:
iast
Declare a structure to hold a student’s information.Read student data from the
lgo
user.Compute the total and average marks for each student.Display the student
ga
information along with total and average marks in a sorted order based on the
9@
OutputStudent information (name, roll number, total marks, average marks) sorted by
li.2
between 1 and 100.Roll numbers are unique integers between 1 and 1000.Marks
de
should be in the range of 0.0 to 100.0.Use appropriate data types to store student
a(
Declare and use a structure to represent student data.Manage data entry and
e
De
Output:Name: John Doe , Roll Number: 101, Total Marks: 255.00, Average Marks:
85.00
Concepts Included:
gu 28 1st semester c programming
Language Used: C
Source Code:
#include <stdio.h>
#include <string.h>
struct Student {
char name[51];
int roll_number;
float marks[3];
float total_marks;
)
float average_marks;
.in
};
ac
void calculate_total_and_average(struct Student *s) {
ty.
rsi
s->total_marks = s->marks[0] + s->marks[1] + s->marks[2];
ive
s->average_marks = s->total_marks / 3.0;
}
un
ias
void sort_students(struct Student *students, int n) {
for (int i = 0; i < n - 1; i++) { t
lgo
for (int j = 0; j < n -i - 1; j++) {
ga
students[j + 1] = temp;
1
}
e1
}
cs
}
4s
}
li.2
int main() {
a
ep
int n;
de
a(
scanf("%d", &n);
m
er
scanf("%d", &students[i].roll_number);
for (int j = 0; j < 3; j++) {
scanf("%f", &students[i].marks[j]);
}
calculate_total_and_average(&students[i]);
}
sort_students(students, n);
for (int i = 0; i < n; i++) {
printf("Name: %s, Roll Number: %d, Total Marks: %.2f, Average Marks: %.2f\n",
students[i].name, students[i].roll_number, students[i].total_marks,
students[i].average_marks);
}
return 0;
}
Compilation Details:
TestCase1:
Input:
< hidden >
Expected Output:
< hidden >
Output:
Name: John Doe , Roll Number: 101, Total Marks: 255.00, Average Marks: 85.00
)
.in
Compilation Status: Passed
ac
ty.
Execution Time:
rsi
ive
0.001s
un
TestCase2: iast
lgo
ga
Input:
9@
Expected Output:
1
e1
cs
Output:
li.2
a
ep
Name: Alex Johnson, Roll Number: 201, Total Marks: 268.50, Average Marks: 89.50
de
Name: Betty White , Roll Number: 202, Total Marks: 246.50, Average Marks: 82.17
a(
Name: Charlie Brown , Roll Number: 203, Total Marks: 210.00, Average Marks: 70.00
m
er
Execution Time:
e
De
0.001s
Devices:
Output:Results of the operations including the updated control registers and binary
)
.in
representation.
ac
ty.
Sample Input:170 85Operation: Grant Lights to User AOperation: Revoke Music
rsi
System from User B
ive
Sample Output:User A Control Register after Granting Lights: 171User B Control
un
Register after Revoking Music System: 85User A has control over Cameras:
ias
YesCombined Control Register (User C): 255User A Control Register in Binary:
t
lgo
10101011
ga
program correctly handles edge cases like no permissions (0) and full permissions
80
(255).
1
e1
Example:Assume user A has the control register 10101010 (170 in decimal) and user
cs
4s
Grant the Lights control to User A.Revoke the Music System control from User
a
ep
B.Check if User A has control over the Cameras.Combine User A and User B's control
de
registers to create User C's control register.Display User C's control register in binary
a(
format.
m
er
li V
Concepts Included:
gu 28 1st semester c programming
Language Used: C
Source Code:
#include <stdio.h>
void display_binary(int control_register) {
)
.in
}
ac
combined = userA | userB;
ty.
printf("Combined Control Register (User C): %d\n", combined);
rsi
printf("User A Control Register in Binary: ");
ive
un
display_binary(userA);
iast
lgo
return 0;
}
ga
9@
14
Compilation Details:
80
1
e1
TestCase1:
cs
4s
Input:
li.2
a
Expected Output:
a(
m
Output:
pa
e
TestCase2:
Input:
< hidden >
Expected Output:
< hidden >
Output:
User A Control Register after Granting Lights: 35
User B Control Register after Revoking Music System: 12
User A has control over Cameras: No
Combined Control Register (User C): 47
User A Control Register in Binary: 00100011
)
.in
Execution Time:
ac
ty.
0.001s
rsi
ive
un
10. Problem StatementTitle: Network Packet Manipulation
ias
t
Scenario-Based Problem:In a specific network communication system, the data is
lgo
transmitted in the form of packets. Each packet contains metadata in the form of an
ga
8-bit header that encodes various properties such as packet type, priority, encryption
9@
status, and error flags. The bits in the header have the following significance:
14
80
Bit 0: Packet Type (0 for data, 1 for control)Bit 1: Priority (0 for low, 1 for high)Bit 2:
1
You are tasked with writing a program to manipulate this packet header using bitwise
li.2
operators. The program should perform the following operations based on user input:
a
ep
Toggle the Packet Type.Set the Priority to High.Clear the Encryption Status (set to
de
unencrypted).Check if an error is detected.Shift the header left by 1 bit and check the
a(
new value.
m
er
li V
Input:
pa
e
De
Output:
The resulting packet header after performing the specified operations, both in
decimal and binary format.
Constraints:
The header of the packet is an 8-bit integer (which values between 0 and
255).Operations must be performed using bitwise operators.The program should
handle edge cases where all bits are set to 0 or 1.
Example:
Step 1: Toggle the Packet Type.The initial header is 11010010. Toggling the Packet
Type (Bit 0) flips the first bit, changing the header to 11010011 (211 in decimal).Step
2: Set the Priority to High.The current header is 11010011. Setting the Priority to High
(Bit 1) ensures the second bit is set to 1, but it is already 1, so the header remains
11010011 (211 in decimal).Step 3: Clear the Encryption Status.The current header is
11010011. Clearing the Encryption Status (Bit 2) sets the third bit to 0, changing the
header to 11010001 (209 in decimal).Step 4: Check if an error is detected.The current
header is 11010001. Checking if an error is detected (Bit 3) shows that the fourth bit
)
.in
is 1, indicating an error is present.Step 5: Shift the header left by 1 bit.The current
ac
header is 11010001. Shifting the header left by 1 bit shifts all bits left, resulting in
ty.
10100010 (162 in decimal).
rsi
ive
un
Completion Status: Completed
ias
t
lgo
Concepts Included:
ga
9@
Language Used: C
1
e1
cs
4s
Source Code:
li.2
#include <stdio.h>
a
ep
}
er
li V
printf("\n");
}
pa
int main() {
e
De
int header;
scanf("%d", &header);
header ^= (1 << 0);
header |= (1 << 1);
printf("New Header in Decimal: %d\n", header);
printf("New Header in Binary: ");
display_binary(header);
header &= ~(1 << 2);
printf("New Header after clearing encryption status: %d\n", header);
printf("New Header in Binary: ");
display_binary(header);
if ((header >> 3) & 1) {
printf("Error Detected: Yes\n");
} else {
Compilation Details:
TestCase1:
)
.in
ac
Input:
ty.
rsi
< hidden >
ive
Expected Output:
un
< hidden >
ias
t
lgo
ga
Output:
9@
Error Detected: No
4s
Execution Time:
m
er
0.001s
li V
pa
e
TestCase2:
De
Input:
< hidden >
Expected Output:
< hidden >
Output:
New Header in Decimal: 211
New Header in Binary: 11010011
New Header after clearing encryption status: 211
New Header in Binary: 11010011
Error Detected: No
Header after Left Shift by 1 Bit: 422
New Header in Binary: 10100110
You are tasked with developing a program for a bank to manage multiple transactions
)
.in
on a customer's account. The bank account holds an integer balance, and
ac
transactions are applied sequentially using various assignment operators. Each
ty.
transaction can be a deposit, withdrawal, interest application, fee deduction, or
rsi
investment. The operations to be performed on the balance are specified by the
ive
customer.
un
ias
The assignment operators involved include:
t
lgo
=: Assign a new balance.+=: Deposit an amount.-=: Withdraw an amount.*=: Apply a
ga
multiplication factor (e.g., interest rate)./=: Apply a division factor (e.g., service fee).
9@
%=: Apply a modulo operation (e.g., remainder after dividing by a certain number).&=:
14
XOR operation.<<=: Apply a left shift operation (e.g., doubling balance).>>=: Apply a
1
right shift operation (e.g., halving balance).The program should read an initial balance
e1
cs
and a sequence of transactions, apply the operations accordingly, and output the final
4s
Input:
ep
de
An integer representing the initial balance.A series of operations and values, each
a(
Output:
pa
e
De
Constraints:
The balance should always be a positive integer and can only go to zero if all funds
are withdrawn or due to bitwise operations.The operations and values provided must
be valid and within the allowable integer range for 32-bit signed integers.The program
should handle edge cases like division by zero, large multiplications, and overflow
scenarios.
Example:
Assume the initial balance is 1000.
Concepts Included:
gu 28 1st semester c programming
)
.in
ac
ty.
Language Used: C
rsi
ive
Source Code:
un
ias
#include <stdio.h>
t
lgo
int main() {
ga
double balance;
9@
char operation[3];
double value;
14
scanf("%lf", &balance);
80
1
e1
while(1) {
cs
scanf("%s", operation);
4s
li.2
if(operation[0] == 'q')
a
ep
break;
de
a(
switch(operation[0]) {
m
case '+':
er
scanf("%lf", &value);
li V
balance += value;
pa
break;
e
De
case '-':
scanf("%lf", &value);
balance -= value;
break;
case '*':
scanf("%lf", &value);
balance *= value; // Apply multiplication with floating-point value
break;
case '/':
scanf("%lf", &value);
if(value != 0)
balance /= value;
break;
case '%':
scanf("%lf", &value);
balance = (int)balance % (int)value;
break;
case '&':
scanf("%lf", &value);
balance = (int)balance & (int)value;
break;
case '|':
scanf("%lf", &value);
balance = (int)balance | (int)value;
break;
case '^':
scanf("%lf", &value);
)
.in
balance = (int)balance ^ (int)value;
ac
break;
ty.
case '<':
rsi
ive
balance = (int)balance << 1;
un
ias
break;
t
lgo
case '>':
balance = (int)balance >> 1;
ga
break;
9@
}
14
}
80
1
e1
return 0;
4s
}
li.2
a
ep
Compilation Details:
de
a(
TestCase1:
m
er
li V
Input:
pa
e
Expected Output:
< hidden >
Output:
Final Balance: 715
Expected Output:
< hidden >
Output:
Final Balance: 24
)
Execution Time:
.in
ac
0.001s
ty.
rsi
ive
un
12. Problem StatementTitle: Financial Transaction System with
ias
Precise Calculations
t
lgo
Problem Description:You are developing a financial transaction system for a bank.
ga
The system must handle transactions involving different types of accounts, which
9@
store balances as different data types. The system needs to accurately calculate the
14
total balance across all accounts, considering both implicit and explicit type
80
the total balance of a customer by summing the balances from all three types of
de
accounts. Due to the differences in data types, you need to ensure that conversions
a(
are handled properly to maintain precision. Use implicit and explicit type casting
m
where necessary.
er
li V
Output:A double value representing the total balance across all accounts, calculated
with the highest precision.Constraints:
Concepts Included:
gu 28 1st semester c programming
Language Used: C
Source Code:
)
.in
ac
#include <stdio.h>
ty.
rsi
int main() {
ive
un
int savings_balance;
ias
float current_balance;
t
lgo
double fixed_deposit_balance;
ga
9@
scanf("%d", &savings_balance);
scanf("%f", ¤t_balance);
14
scanf("%lf", &fixed_deposit_balance);
80
1
e1
fixed_deposit_balance;
4s
li.2
return 0;
a(
}
m
er
li V
Compilation Details:
pa
e
De
TestCase1:
Input:
< hidden >
Expected Output:
< hidden >
Output:
Total Balance: 3550001.25
TestCase2:
Input:
< hidden >
Expected Output:
< hidden >
Output:
)
.in
Total Balance: 1151235.34
ac
ty.
Compilation Status: Passed
rsi
ive
Execution Time:
un
ias
0.001s
t
lgo
ga
Manufacturing
14
80
calculating the overall production cost, profit margins, and tax deductions for multiple
cs
products. The program should allow the user to input the cost of raw materials, labor,
4s
and overhead for each product. The program should then compute the following:
li.2
a
Total Production Cost: Calculated as the sum of raw material cost, labor cost, and
ep
Deduction: If the gross profit is greater than ₹100,000, a 15% tax is applied; otherwise,
a(
deduction.Product Status:If the net profit is greater than or equal to ₹75,000, the
er
li V
product is considered "Highly Profitable".If the net profit is between ₹50,000 and
pa
₹74,999, it is considered "Moderately Profitable".If the net profit is less than ₹50,000,
e
Output:For each product, output the total production cost, gross profit, tax deduction,
net profit, and product status.
)
.in
Completion Status: Completed
ac
ty.
Concepts Included:
rsi
ive
gu 28 1st semester c programming
un
Language Used: C ias
t
lgo
ga
9@
Source Code:
14
#include <stdio.h>
80
int main() {
1
e1
int n;
cs
scanf("%d", &n);
4s
0.10;
li V
Compilation Details:
TestCase1:
Input:
< hidden >
Expected Output:
< hidden >
)
.in
Output:
ac
ty.
Product 1:
rsi
Total Production Cost: ₹1000000
ive
Gross Profit: ₹200000.00
un
Tax Deduction: ₹30000.00
ias
Net Profit: ₹170000.00
t
lgo
Product Status: Highly Profitable
Product 2:
ga
Execution Time:
a
ep
de
0.001s
a(
m
er
TestCase2:
li V
Input:
pa
e
De
Expected Output:
< hidden >
Output:
Product 1:
Total Production Cost: ₹450000
Gross Profit: ₹90000.00
Tax Deduction: ₹9000.00
Net Profit: ₹81000.00
Product Status: Highly Profitable
Compilation Status: Passed
Execution Time:
0.001s
)
.in
ac
The rules for determining the action are as follows:
ty.
rsi
Red Light:
ive
If the light is red and an emergency vehicle is approaching, vehicles must allow it to
un
pass by preparing to go.If no emergency vehicle is approaching, vehicles must
ias
stop.Yellow Light:
t
lgo
If the light is yellow, vehicles must prepare to stop.If the light is yellow and an
ga
If the light is green, vehicles should proceed normally.If the light is green and an
1
emergency vehicle is approaching, vehicles must clear the way by pulling over.Based
e1
on the above rules, the program should output the action that vehicles should take.
cs
4s
li.2
Input:
a
ep
The first line contains a single character, T, representing the traffic light's current
de
state. T can be 'R' for Red, 'Y' for Yellow, or 'G' for Green.The second line contains a
a(
no emergency vehicle.
li V
pa
Output:
e
De
Print the action vehicles should take: "ALLOW EMERGENCY", "STOP", "PREPARE TO
STOP", "PROCEED", or "CLEAR THE WAY".
Sample Input:R1
Constraints:
ALLOW EMERGENCY
Concepts Included:
gu 28 1st semester c programming
Language Used: C
)
.in
ac
Source Code:
ty.
rsi
#include <stdio.h>
ive
un
int main() {
iast
lgo
char T;
ga
int E;
9@
scanf("%c", &T);
scanf("%d", &E);
14
if (T == 'R') {
80
if (E == 1) {
1
e1
printf("ALLOW EMERGENCY\n");
cs
} else {
4s
printf("STOP\n");
li.2
}
a
ep
} else if (T == 'Y') {
de
if (E == 1) {
a(
printf("ALLOW EMERGENCY\n");
m
er
} else {
li V
pa
printf("PREPARE TO STOP\n");
e
De
}
} else if (T == 'G') {
if (E == 1) {
printf("CLEAR THE WAY\n");
} else {
printf("PROCEED\n");
}
}
return 0;
}
Compilation Details:
TestCase1:
Input:
< hidden >
Expected Output:
< hidden >
Output:
ALLOW EMERGENCY
)
Execution Time:
.in
ac
0.001s
ty.
rsi
ive
TestCase2:
un
ias
Input:
t
lgo
< hidden >
ga
9@
Expected Output:
14
Output:
cs
4s
PREPARE TO STOP
li.2
Execution Time:
a(
m
0.001s
er
li V
pa
Add a bookSearch for a book by IDDelete a book by IDDisplay all booksExitFor Option
1 (Add a book): The user will input a book ID (integer) and a book title (string).For
Option 2 (Search for a book by ID): The user will input the book ID to search for.For
Option 3 (Delete a book by ID): The user will input the book ID to delete.For Option 4
(Display all books): The program will display all the books currently in the system.For
Option 5 (Exit): The program will terminate.
Output:
For Option 1: The program should confirm that the book was added.For Option 2: The
program should display the book details if found or notify the user if the book is not
found.For Option 3: The program should confirm that the book was deleted or notify
the user if the book ID is not found.For Option 4: The program should list all books in
the system.For Option 5: The program will exit with a message.
Constraints:
)
.in
ac
The system can hold a maximum of 100 books.The book ID must be unique.The title
ty.
should not exceed 50 characters.Input validation should be performed for book ID to
rsi
ensure it is a positive integer.
ive
Example:Input:1. Add a book2. Search for a book by ID3. Delete a book by ID4. Display
un
all books5. Exit
iast
lgo
Choose an option: 1Enter Book ID: 101Enter Book Title: "C Programming Language"
ga
Choose an option: 1Enter Book ID: 102Enter Book Title: "Data Structures in C"
9@
14
Choose an option: 4
e1
cs
Choose an option: 5
a
ep
Explanation:
li V
pa
The user adds two books with IDs 101 and 102. Program usually confirms the
e
addition of each book.The user searches for the book with ID 101, and the program
De
displays its details.The user displays all books, and the program lists the available
book.The user deletes the book with ID 102, and the program confirms the
deletion.The user exits the program.
Concepts Included:
gu 28 1st semester c programming
Language Used: C
Source Code:
#include <stdio.h>
#include <string.h>
#define MAX_BOOKS 100
#define MAX_TITLE_LENGTH 50
typedef struct {
int id;
char title[MAX_TITLE_LENGTH];
} Book;
Book library[MAX_BOOKS];
int bookCount = 0;
void addBook() {
if (bookCount >= MAX_BOOKS) {
)
.in
return;
ac
ty.
}
rsi
int id;
ive
char title[MAX_TITLE_LENGTH];
un
scanf("%d", &id);
ias
getchar();
t
lgo
fgets(title, MAX_TITLE_LENGTH, stdin);
title[strcspn(title, "\n")] = '\0';
ga
library[bookCount].id = id;
9@
strcpy(library[bookCount].title, title);
14
bookCount++;
80
}
cs
void searchBook() {
4s
int id;
li.2
scanf("%d", &id);
a
if (library[i].id == id) {
de
return;
m
er
li V
}
epa
}
De
)
.in
int choice;
ac
while (1) {
ty.
scanf("%d", &choice);
rsi
switch (choice) {
ive
case 1:
un
addBook();
ias
break;
t
lgo
case 2:
searchBook();
ga
break;
9@
case 3:
14
deleteBook();
80
break;
1
e1
case 4:
cs
displayBooks();
4s
break;
li.2
case 5:
a
return 0;
de
}
a(
}
m
er
return 0;
li V
}
pa
e
De
Compilation Details:
TestCase1:
Input:
< hidden >
Expected Output:
< hidden >
Output:
Book added successfully.
Book added successfully.
Book found: ID=101, Title="C Programming Language"
Book ID=101, Title="C Programming Language"
Book ID=102, Title="Data Structures in C"
Book deleted successfully.
Exiting the program...
TestCase2:
)
.in
Input:
ac
ty.
< hidden >
rsi
Expected Output:
ive
un
< hidden >
iast
lgo
Output:
ga
Execution Time:
li.2
a
ep
0.001s
de
a(
m
rooms, each with a different nightly rate. Guests can book a room
e
De
for a range of dates, and your system needs to calculate the total
cost of the stay for each guest. You are tasked with handling the
booking process and calculating the total cost using loops and
conditional statements.
Each booking request consists of:
The room number (R) the guest wants to book.The start date (S) and end date (E) of
their stay.Each room has a rate for the night that depends on the room number.You
need to ensure that:
A booking is only valid if the start date is before or equal to the end date.The system
should calculate the total cost by looping through each night of the guest's stay and
summing the nightly rate for that room.If a guest's booking is invalid, the system
should print "Invalid booking" and skip that request.Your program must handle
multiple booking requests.
OutputFor each valid booking request, output the total cost of the stay for the
guest.For each invalid booking request, output "Invalid booking".
)
Sample Output:600600Invalid booking
.in
ac
ExplanationThe first request is to book Room 1 from day 5 to day 10, so the total cost
ty.
is calculated as 6 * 100 = 600.The second request is to book Room 2 from day 12 to
rsi
day 15, so the total cost is 4 * 150 = 600.The third request is invalid because the start
ive
date is after the end date, so the system outputs "Invalid booking".
un
iast
lgo
Completion Status: Completed
ga
9@
Concepts Included:
14
80
Language Used: C
4s
li.2
a
Source Code:
ep
de
#include <stdio.h>
a(
int main() {
m
int N, R, S, E;
er
li V
int roomRates[10] = {100, 150, 200, 250, 300, 350, 400, 450, 500, 550};
pa
scanf("%d", &N);
e
continue;
}
int nights = E - S + 1;
int totalCost = nights * roomRates[R - 1];
printf("%d\n", totalCost);
}
return 0;
}
Compilation Details:
TestCase1:
Input:
< hidden >
Expected Output:
< hidden >
Output:
2100
)
1200
.in
ac
Compilation Status: Passed
ty.
rsi
Execution Time:
ive
un
0.001s
iast
lgo
TestCase2:
ga
9@
Input:
14
Expected Output:
cs
4s
Output:
a
ep
de
200
a(
Invalid booking
m
1650
er
li V
Execution Time:
De
0.001s
OutputFor each "RESERVE X" command, output "Room Reserved" if the room was
successfully reserved, or "Room Already Reserved by Employee Y" if the room is
already reserved by another employee, where Y is the employee ID who holds the
reservation.For each "FREE X" command, output "Room Freed" if the room is freed by
the employee who reserved it, or "No Reservation to Free" if no reservation exists or
the reservation doesn't match the given employee ID.
)
.in
Sample Output:Room ReservedRoom Already Reserved by Employee 101Room
ac
FreedRoom ReservedRoom Freed
ty.
rsi
ExplanationThe first request "RESERVE 101" successfully reserves the room for
ive
employee 101.The second request "RESERVE 102" fails because the room is already
un
reserved by employee 101.The third request "FREE 101" successfully frees the
ias
room.The fourth request "RESERVE 102" successfully reserves the room for
employee 102.The fifth request "FREE 102" successfully frees the room.
t
lgo
ga
9@
Concepts Included:
e1
cs
Language Used: C
a
ep
de
a(
Source Code:
m
er
#include <stdio.h>
li V
#include <string.h>
pa
int main() {
e
char command[10];
scanf("%d", &N);
for (int i = 0; i < N; i++) {
scanf("%s %d", command, &employeeID);
if (strcmp(command, "RESERVE") == 0) {
if (currentReservation == -1) {
currentReservation = employeeID;
goto room_reserved;
} else if (currentReservation == employeeID) {
goto already_reserved_by_same;
} else {
goto already_reserved_by_other;
}
} else if (strcmp(command, "FREE") == 0) {
if (currentReservation == employeeID) {
currentReservation = -1;
goto room_freed;
} else if (currentReservation == -1) {
goto no_reservation;
} else {
goto reservation_does_not_match;
}
}
continue;
room_reserved:
printf("Room Reserved\n");
continue;
)
.in
already_reserved_by_same:
ac
ty.
printf("Room Already Reserved by Employee %d\n", currentReservation);
rsi
ive
continue;
un
already_reserved_by_other:
ias
printf("Room Already Reserved by Employee %d\n", currentReservation);
t
lgo
continue;
room_freed:
ga
printf("Room Freed\n");
9@
continue;
14
no_reservation:
80
continue;
cs
reservation_does_not_match:
4s
continue;
a
}
ep
return 0;
de
}
a(
m
er
Compilation Details:
li V
pa
e
TestCase1:
De
Input:
< hidden >
Expected Output:
< hidden >
Output:
Room Reserved
Room Freed
Room Reserved
Compilation Status: Passed
Execution Time:
0.001s
TestCase2:
Input:
< hidden >
Expected Output:
< hidden >
)
.in
Output:
ac
ty.
Room Reserved
rsi
Room Already Reserved by Employee 301
ive
Room Freed
un
Room Reserved
Execution Time:
9@
14
0.001s
80
1
e1
cs
international shipments.
m
er
li V
Weight Category: This function will bascially determine the weight category of the
e
De
package.Cost Calculation: This function calculates the shipment cost based on the
weight category and distance.Cost Display: This function displays the final cost along
with the details of the shipment.Weight Categories:Lightweight: 0 < weight ≤ 5
kgStandard: 5 < weight ≤ 20 kgHeavy: 20 < weight ≤ 50 kgOverweight: weight > 50
kgRate Table (per km):Domestic:Lightweight: $1.00Standard: $1.50Heavy:
$2.00Overweight: $3.00International:Lightweight: $2.00Standard: $3.00Heavy:
$4.00Overweight: $6.00
InputThe first line will contain an integer N which represents the number of
packages.The next N lines contain:A float W representing the weight of the
package.An integer D will represent the distance in kilometers.A string T will
represent the type of shipment ("domestic" or "international").
OutputFor each package, output the weight category, shipment type, and the
calculated cost, each on a new line.
Constraints1 ≤ N ≤ 500 < W ≤ 1001 ≤ D ≤ 10000T is either "domestic" or "international"
OutputLightweightdomestic1000.00Standardinternational6000.00Overweightdomest
ic15000.00
)
.in
ac
Concepts Included:
ty.
rsi
gu 28 1st semester c programming
ive
un
Language Used: C
iast
lgo
Source Code:
ga
9@
#include <stdio.h>
14
#include <string.h>
80
return "Lightweight";
li.2
return "Standard";
a(
return "Heavy";
er
li V
} else {
e
De
return "Invalid";
}
}
// Function to calculate the cost
float calculateCost(const char* weightCategory, int distance, const char*
shipmentType) {
float rate = 0.0;
if (strcmp(shipmentType, "domestic") == 0) {
if (strcmp(weightCategory, "Lightweight") == 0) rate = 1.00;
else if (strcmp(weightCategory, "Standard") == 0) rate = 1.50;
else if (strcmp(weightCategory, "Heavy") == 0) rate = 2.00;
else if (strcmp(weightCategory, "Overweight") == 0) rate = 3.00;
} else if (strcmp(shipmentType, "international") == 0) {
if (strcmp(weightCategory, "Lightweight") == 0) rate = 2.00;
else if (strcmp(weightCategory, "Standard") == 0) rate = 3.00;
else if (strcmp(weightCategory, "Heavy") == 0) rate = 4.00;
else if (strcmp(weightCategory, "Overweight") == 0) rate = 6.00;
}
}
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
float weight;
int distance;
char shipmentType[15];
)
.in
scanf("%f %d %s", &weight, &distance, shipmentType);
ac
const char* weightCategory = determineWeightCategory(weight);
ty.
if (strcmp(weightCategory, "Invalid") == 0) {
rsi
printf("Invalid weight\n");
ive
continue;
un
}
ias
float cost = calculateCost(weightCategory, distance, shipmentType);
t
lgo
printf("%s\n", weightCategory);
printf("%s\n", shipmentType);
ga
9@
printf("%.2f\n", cost);
14
80
}
1
e1
return 0;
cs
}
4s
li.2
Compilation Details:
a
ep
de
TestCase1:
a(
m
er
Input:
li V
pa
Expected Output:
< hidden >
Output:
Standard
domestic
2250.00
Heavy
international
12000.00
TestCase2:
Input:
< hidden >
Expected Output:
< hidden >
Output:
)
.in
Standard
ac
international
ty.
15000.00
rsi
ive
Compilation Status: Passed
un
ias
Execution Time:
t
lgo
0.001s
ga
9@
14
Each order includes a list of items, each with a specific quantity and
cs
Calculate the total cost of each order.Apply a discount based on the total cost of the
a
ep
order.Determine the final price after applying the discount.The system should handle
de
multiple orders and output the final price for each order.
a(
m
function calculates the total cost of an order based on the prices and quantities of
li V
cost. The discount is as follows:If the total cost is less than $50, then there will be no
e
De
discount.If the total cost is between $50 and $100, a 10% discount.If the total cost is
more than $100, a 20% discount.finalPriceAfterDiscount(float totalCost): This
function calculates the final price after applying the discount.
InputThe first line contains an integer N representing the number of orders.The next N
lines each contain:An integer M representing the number of items in the order.M pairs
of floating-point numbers where each pair represents the price and quantity of an
item.
OutputFor each order, output the final price after applying the discount, rounded to
two decimal places.
Concepts Included:
)
.in
gu 28 1st semester c programming
ac
ty.
Language Used: C
rsi
ive
un
Source Code:
#include <stdio.h> ias
t
lgo
ga
}
return totalCost;
a
ep
}
de
return 0.0;
er
li V
} else {
e
De
float prices[M];
int quantities[M];
printf("%.2f\n", finalPrice);
}
)
.in
ac
return 0;
ty.
}
rsi
ive
Compilation Details:
un
iast
lgo
TestCase1:
ga
Input:
9@
14
Expected Output:
e1
cs
Output:
a
ep
88.00
de
a(
Execution Time:
li V
pa
0.001s
e
De
TestCase2:
Input:
< hidden >
Expected Output:
< hidden >
Output:
81.00
62.10
Compilation Status: Passed
Execution Time:
0.001s
)
.in
Discount Tiers:
ac
ty.
Tier 1: 5% discount for 1 to 5 items.Tier 2: 10% discount for 6 to 10 items.Tier 3: 15%
rsi
discount for more than 10 items.Your task is to:
ive
un
Calculate the total cost of items before applying the discount.Apply the discount
ias
based on the total number of items.Return the final cost after applying the specific
amount of discount. t
lgo
ga
InputThe first line contains an integer N representing the number of items in the
cs
cart.The second line contains N integers where each integer represents the price of
4s
an item.
li.2
OutputOutput the final cost of the items in the cart after applying the discount,
a
ep
Sample Input:430 20 50 40
li V
pa
Sample Output:133.00
e
De
Concepts Included:
gu 28 1st semester c programming
Language Used: C
Source Code:
#include <stdio.h>
return 0;
}
return items[n - 1] + calculateTotalCost(items, n - 1);
}
float applyDiscount(float totalCost, int itemCount) {
float discount = 0.0;
if (itemCount >= 1 && itemCount <= 5) {
)
.in
discount = 0.05 * totalCost;
ac
} else if (itemCount >= 6 && itemCount <= 10) {
ty.
discount = 0.10 * totalCost;
rsi
} else if (itemCount > 10) {
ive
discount = 0.15 * totalCost;
un
}
ias
return totalCost - discount;
t
lgo
}
int main() {
ga
int N;
9@
scanf("%d", &N);
14
80
int items[N];
1
e1
scanf("%d", &items[i]); }
4s
printf("%.2f\n", finalCost);
m
er
li V
return 0;
pa
}
e
De
Compilation Details:
TestCase1:
Input:
< hidden >
Expected Output:
< hidden >
Output:
142.50
TestCase2:
Input:
< hidden >
Expected Output:
)
.in
< hidden >
ac
ty.
Output:
rsi
ive
288.00
un
ias
Compilation Status: Passed
t
lgo
Execution Time:
ga
9@
0.001s
14
80
1
OutputFor each employee, output the final bonus amount after applying the
adjustment, rounded to two decimal places.
Sample Output875.00712.50650.00
)
.in
before adjustment = 4500.00 + 500.00 = 5000.00Adjustment (full-time) = 0%Final
ac
bonus = 5000.00
ty.
rsi
ive
Completion Status: Completed
un
iast
lgo
Concepts Included:
ga
Language Used: C
1
e1
cs
Source Code:
4s
li.2
#include <stdio.h>
a
}
er
li V
}
De
printf("%.2f\n", finalBonus);
}
return 0;
}
)
Compilation Details:
.in
ac
ty.
TestCase1:
rsi
ive
Input:
un
ias
< hidden >
t
lgo
Expected Output:
ga
9@
Output:
80
1
e1
875.00
cs
712.50
4s
650.00
li.2
Execution Time:
a(
m
0.001s
er
li V
pa
TestCase2:
e
De
Input:
< hidden >
Expected Output:
< hidden >
Output:
3500.00
4227.50
5350.00
You are given an array arr of size n consisting of integers and two additional integers
x and y. Your task is to implement a function transformArray(arr, n, x, y) that performs
the following operations:
Element Replacement: Traverse the array, and for every element arr[i], if it is divisible
by x, replace it with y.Incremental Sum Update: After the replacement, for each index i
from 0 to n-2, set arr[i] to the sum of itself and the next element (arr[i] = arr[i] +
)
.in
arr[i+1]). The last element of the array remains unchanged.Output Maximum Value:
ac
Return the maximum value from the modified array.
ty.
rsi
Input:The first line contains an integer n (1 ≤ n ≤ 10^5), which is the size of the
ive
array.The second line contains n space-separated integers representing the elements
un
of the array arr (0 ≤ arr[i] ≤ 10^9).The third line contains two integers x and y (1 ≤ x, y ≤
ias
10^9).
t
lgo
Output:Print a single integer, which is the maximum value in the array after
ga
Sample Output:12
1
e1
cs
Constraints:The array size n can be large.Elements of the array can be as large as one
4s
Concepts Included:
gu 28 1st semester c programming
Language Used: C
Source Code:
#include <stdio.h>
)
.in
}
ac
}
ty.
rsi
// Step 2: Incremental Sum Update
ive
for (int i = 0; i < n - 1; i++) {
un
arr[i] = arr[i] + arr[i + 1];
ias
}
t
lgo
// Step 3: Find and return the maximum value
ga
maxVal = arr[i];
1
e1
}
cs
}
4s
li.2
return maxVal;
a
}
ep
int main() {
de
a(
int n;
m
er
li V
scanf("%d", &n);
epa
int arr[n];
De
int x, y;
scanf("%d %d", &x, &y);
return 0;
}
Compilation Details:
TestCase1:
Input:
< hidden >
Expected Output:
< hidden >
Output:
12
)
.in
Compilation Status: Passed
ac
ty.
Execution Time:
rsi
ive
0.001s
un
TestCase2: ias
t
lgo
ga
Input:
9@
Expected Output:
1
e1
cs
Output:
li.2
a
ep
6
de
Execution Time:
li V
pa
0.001s
e
De
You are tasked with implementing a function that manipulates a doubly linked list
using the concept of call by address. The linked list contains integer nodes, and you
need to perform the following operations on the list:
Reverse the List: Reverse the entire linked list.Remove Duplicates: After reversing,
remove all duplicate elements from the list, retaining only the first occurrence of each
element.Insert Sum at End: After removing duplicates, calculate the sum of all the
elements in the linked list and insert this sum as a new node at the end of the
list.These operations should be done by passing the head of the list to the function by
using a call by address.
Input:The first line contains an integer n (1 ≤ n ≤ 10^5), the number of nodes in the
linked list.The next line contains n space-separated integers representing the
elements of the linked list.
Output:Print the elements of the modified linked list after performing all the
operations.
Sample Input:74 3 2 3 4 5 2
Sample Output:2 5 4 3 14
)
.in
Example:Consider a linked list with n = 7 and the elements 4 -> 3 -> 2 -> 3 -> 4 -> 5 ->
ac
2.
ty.
rsi
Step 1: Reverse the List
ive
un
The list becomes: 2 -> 5 -> 4 -> 3 -> 2 -> 3 -> 4Step 2: Remove Duplicates
ias
The list after removing duplicates: 2 -> 5 -> 4 -> 3Step 3: Insert Sum at End
t
lgo
ga
The sum of the elements is 2 + 5 + 4 + 3 = 14.The final list is: 2 -> 5 -> 4 -> 3 -> 14.
9@
14
Concepts Included:
4s
li.2
Language Used: C
a(
m
Source Code:
er
li V
#include <stdio.h>
pa
#include <stdlib.h>
e
De
struct Node {
int data;
struct Node* next;
struct Node* prev;
};
if (temp != NULL) {
*head = temp->prev;
}
}
void removeDuplicates(struct Node** head) {
struct Node* current = *head;
struct Node* prev = NULL;
struct Node* temp = NULL;
)
.in
temp = current->next;
ac
ty.
rsi
ive
while (temp != NULL) {
un
if (current->data == temp->data) {
ias
prev->next = temp->next;
t
lgo
if (temp->next != NULL) {
temp->next->prev = prev;
ga
}
9@
free(temp);
14
temp = prev->next;
80
} else {
1
e1
prev = temp;
cs
temp = temp->next;
4s
}
li.2
}
a
current = current->next;
ep
}
de
}
a(
int sum = 0;
e pa
sum += current->data;
current = current->next;
}
struct Node* newNode = (struct Node*)malloc(sizeof(struct Node));
newNode->data = sum;
newNode->next = NULL;
current = *head;
while (current->next != NULL) {
current = current->next;
}
current->next = newNode;
newNode->prev = current;
}
void printList(struct Node* head) {
struct Node* temp = head;
while (temp != NULL) {
printf("%d ", temp->data);
temp = temp->next;
}
printf("\n");
}
void append(struct Node** head, int new_data) {
struct Node* new_node = (struct Node*)malloc(sizeof(struct Node));
struct Node* last = *head;
new_node->data = new_data;
new_node->next = NULL;
)
.in
ac
if (*head == NULL) {
ty.
new_node->prev = NULL;
rsi
*head = new_node;
ive
return;
un
}
iast
lgo
while (last->next != NULL) {
last = last->next;
ga
}
9@
14
last->next = new_node;
80
new_node->prev = last;
1
e1
}
cs
int main() {
4s
int n;
li.2
scanf("%d", &n);
a
ep
int data;
li V
scanf("%d", &data);
epa
append(&head, data);
De
reverseList(&head);
removeDuplicates(&head);
insertSumAtEnd(&head);
printList(head);
return 0;
}
Compilation Details:
TestCase1:
Input:
< hidden >
Expected Output:
< hidden >
Output:
2 5 4 3 14
)
Execution Time:
.in
ac
0.001s
ty.
rsi
ive
TestCase2:
un
ias
Input:
t
lgo
< hidden >
ga
9@
Expected Output:
14
Output:
cs
4s
5 4 3 2 1 15
li.2
Execution Time:
a(
m
0.001s
er
li V
pa
Problem Statement:You are given an array of integers, and you need to find the
maximum difference between any two elements in the array. The difference is defined
as the absolute difference between the two elements. The array may contain both
positive and negative numbers, and your task is to ensure the difference calculation
considers all possible pairs within the array.
Input:
The first line contains an integer N (1 ≤ N ≤ 1000) representing the number of
elements in the array.The second line contains N space-separated integers
representing the elements of the array A[i] (-10^5 ≤ A[i] ≤ 10^5).
Output:
A single integer, the maximum difference between any two elements in the array.
Constraints:
Example:
Example 1:Input:51 -3 2 10 6
Output:13
Explanation:The maximum difference is between -3 and 10, which is |10 - (-3)| = 13.
)
.in
Completion Status: Completed
ac
ty.
rsi
Concepts Included:
ive
un
gu 28 1st semester c programming
iast
lgo
Language Used: C
ga
9@
Source Code:
14
80
#include <stdio.h>
1
e1
#include <limits.h>
cs
4s
li.2
int main() {
int N;
a
ep
scanf("%d", &N);
de
a(
int arr[N];
m
scanf("%d", &arr[i]);
e
De
printf("%d\n", max_diff);
return 0;
}
Compilation Details:
TestCase1:
Input:
< hidden >
Expected Output:
< hidden >
Output:
0
)
.in
Compilation Status: Passed
ac
ty.
Execution Time:
rsi
ive
0.001s
un
TestCase2: iast
lgo
ga
Input:
9@
Expected Output:
1
e1
cs
Output:
li.2
a
ep
20
de
Execution Time:
li V
pa
0.001s
e
De
Input Format:The first line contains an integer n (where 2 ≤ n ≤ 500), representing the
size of the matrix.The next n lines each contain n integers (either 0 or 1), representing
the matrix.
Output Format:Output a single integer, the minimum number of cells that need to be
flipped to restore the matrix to a proper chessboard pattern.
Constraints:2 ≤ n ≤ 500
Each cell in the matrix is either 0 or 1.The matrix may have at most 50% of its cells
corrupted.
Example:Input:41 0 1 00 1 0 11 1 0 00 0 1 1
Output:4
Pattern 1:1 0 1 00 1 0 11 0 1 00 1 0 1
Pattern 2:0 1 0 11 0 1 00 1 0 11 0 1 0
)
.in
ac
We compare the given matrix with both Pattern 1 and Pattern 2. For Pattern 1, we
ty.
need to flip the two bottom-right cells to make the matrix valid. For Pattern 2, we
rsi
would need to flip more cells, so the optimal solution is to follow Pattern 1 with a total
ive
of 2 flips.
un
Completion Status: Completed iast
lgo
ga
9@
Concepts Included:
14
80
Language Used: C
4s
li.2
Source Code:
a
ep
de
#include <stdio.h>
a(
int main() {
m
int n;
er
scanf("%d", &n);
li V
int matrix[n][n];
pa
if(matrix[i][j] != 0) pattern2++;
} else {
if(matrix[i][j] != 0) pattern1++;
if(matrix[i][j] != 1) pattern2++;
}
}
}
if(pattern1 < pattern2) printf("%d\n", pattern1);
else printf("%d\n", pattern2);
return 0;
}
Compilation Details:
TestCase1:
Input:
)
.in
ac
< hidden >
ty.
rsi
Expected Output:
ive
< hidden >
un
ias
Output: lgo
t
0
ga
9@
Execution Time:
1
e1
0.001s
cs
4s
li.2
TestCase2:
a
ep
Input:
de
a(
Expected Output:
li V
pa
Output:
1
Input:The first line contains two integers n and m (1 ≤ n, m ≤ 1000), representing the
dimensions of the grid.The next n lines each contain m space-separated integers
representing the elements of the grid (0 ≤ grid[i][j] ≤ 2).
Output:Print a single integer, the number of distinct islands found in the grid.
)
.in
Constraints:The grid dimensions n and m can be large, up to 1000x1000.The grid
ac
values can be 0, 1, or 2.You should use an efficient algorithm to handle the large input
ty.
size.
rsi
ive
Example:Consider the following grid with n = 5 and m = 6:
un
Input:5 61 0 0 0 0 00 1 1 0 2 00 0 0 1 0 01 0 0 2 1 10 0 0 0 0 1
iast
lgo
Output:2
ga
Concepts Included:
de
a(
Language Used: C
pa
e
De
Source Code:
#include <stdio.h>
#define MAX_N 1000
#define MAX_M 1000
int grid[MAX_N][MAX_M];
int visited[MAX_N][MAX_M];
int n, m;
int directions[8][2] = {
{1, 0}, {-1, 0}, {0, 1}, {0, -1},
{1, 1}, {1, -1}, {-1, 1}, {-1, -1}
};
void dfs(int x, int y) {
visited[x][y] = 1;
for (int i = 0; i < 8; i++) {
int nx = x + directions[i][0];
int ny = y + directions[i][1];
if (nx >= 0 && ny >= 0 && nx < n && ny < m && !visited[nx][ny] && (grid[nx][ny] == 1 ||
grid[nx][ny] == 2)) {
dfs(nx, ny);
}
}
}
int countIslands(int grid[][MAX_M], int n, int m) {
int islandCount = 0;
)
.in
ac
for (int i = 0; i < n; i++) {
ty.
for (int j = 0; j < m; j++) {
rsi
if (!visited[i][j] && (grid[i][j] == 1 || grid[i][j] == 2)) {
ive
dfs(i, j);
un
islandCount++;
ias
}
t
lgo
}
}
ga
9@
return islandCount;
14
}
80
1
e1
int main() {
cs
4s
scanf("%d", &grid[i][j]);
a(
visited[i][j] = 0;
m
er
}
li V
}
epa
printf("%d\n", result);
return 0;
}
Compilation Details:
TestCase1:
Input:
< hidden >
Expected Output:
< hidden >
Output:
2
TestCase2:
)
.in
Input:
ac
ty.
< hidden >
rsi
ive
Expected Output:
un
ias
< hidden >
t
lgo
Output:
ga
9@
2
14
Execution Time:
cs
4s
0.001s
li.2
a
ep
lifetime by:
pa
Declaring a global variable to keep track of the total number of transactions across all
e
De
accounts. Declaring static variables within functions to maintain the balance of each
account. Using local variables to handle individual transaction details. The program
should perform the following tasks:
Initialize a given number of accounts with starting balances. Allow the user to
perform a sequence of transactions (deposit or withdraw) on any account. Display
the balance of an account after each transaction. At the end, display the total number
of transactions made.
InputAn integer n (number of accounts, where 1 <= n <= 10). n initial account
balances as floating-point numbers. An integer t (number of transactions, where 1 <=
t <= 50). For each transaction: An integer account_number (1 to n) indicating the
target account. A character type ('D' for deposit, 'W' for withdrawal). A floating-point
number amount (transaction amount).
OutputThe balance of the specified account after each transaction. The total number
of transactions performed. Constraints The number of accounts n must be between 1
and 10. The number of transactions t must be between 1 and 50. Transaction
amounts should be in the range of 0.01 to 1,000,000.00. Withdrawals should not
exceed the current balance of the account. Accounts are 1-indexed (account numbers
start from 1).
Global Variables: Used to maintain data that should be accessible across different
functions. Static Local Variables: Used to maintain state within a function, persisting
across multiple calls. Local Variables: Used for temporary data that is limited to the
function scope.
)
.in
750.00 3 W 1500.00 Output: Account 1 Balance: 1500.00 Account 2 Balance:
ac
1750.00 Account 3 Balance: 4000.00 Account 1 Balance: 750.00 Account 3 Balance:
ty.
2500.00 Total Transactions: 5
rsi
ive
un
Completion Status: Completed
iast
lgo
Concepts Included:
ga
9@
Language Used: C
1
e1
cs
4s
Source Code:
li.2
#include <stdio.h>
a
ep
de
int total_transactions = 0;
a(
m
{
pa
if (type == 'D')
e
De
{
balances[an] += amount;
printf("Account %d Balance: %.2f\n", an, balances[an]);
}
else if (type == 'W')
{
if (amount > balances[an])
{
printf("Insufficient balance in Account %d\n", an);
}
else
{
balances[an] -= amount;
printf("Account %d Balance: %.2f\n", an, balances[an]);
}
}
total_transactions++;
}
int main()
{
int n;
int t;
scanf("%d", &n);
float balances[10];
for (int i = 1; i <= n; i++)
{
)
.in
scanf("%f", &balances[i]);
ac
}
ty.
rsi
scanf("%d", &t);
ive
un
for (int i = 0; i < t; i++)
ias
{
t
lgo
int a_n;
char type;
ga
float amount;
9@
14
}
4s
li.2
return 0;
de
}
a(
m
er
Compilation Details:
li V
pa
e
TestCase1:
De
Input:
< hidden >
Expected Output:
< hidden >
Output:
Account 1 Balance: 6500.00
Account 2 Balance: 2000.00
Account 1 Balance: 4500.00
Total Transactions: 3
Compilation Status: Passed
Execution Time:
0.001s
TestCase2:
Input:
< hidden >
Expected Output:
< hidden >
)
.in
Output:
ac
ty.
Account 3 Balance: 1700.00
rsi
Account 4 Balance: 500.00
ive
Account 1 Balance: 4000.00
un
Account 2 Balance: 2500.00
ias
Total Transactions: 4
t
lgo
Compilation Status: Passed
ga
9@
Execution Time:
14
80
0.002s
1
e1
cs
4s
Problem Description:
a
ep
de
Given an array of n integers, your task is to find the maximum product of any
a(
contiguous subarray. The subarray must contain at least one element, and you need
m
maxProductSubarray(int arr[], int n): This function takes the array and its size as
De
Input:The first line contains an integer n (1 ≤ n ≤ 10^5), the size of the array.The
second line contains n space-separated integers representing the elements of the
array arr[i] (-10^5 ≤ arr[i] ≤ 10^5).
The maximum product is obtained by considering the subarray [2, 3, -2, 4] which
yields a product of 48.
Output:48
Concepts Included:
gu 28 1st semester c programming
)
.in
ac
Language Used: C
ty.
rsi
ive
Source Code:
un
ias
#include <stdio.h>
void getInputArray(int arr[], int n) { t
lgo
for (int i = 0; i < n; i++) {
ga
scanf("%d", &arr[i]);
9@
}
14
}
80
currentMax = currentMin;
a(
currentMin = temp;
m
}
er
li V
}
return result;
}
int main() {
int n;
scanf("%d", &n);
int arr[n];
getInputArray(arr, n);
int result = maxProductSubarray(arr, n);
printf("%d\n", result);
return 0;
}
Compilation Details:
TestCase1:
Input:
< hidden >
Expected Output:
< hidden >
Output:
48
)
.in
Compilation Status: Passed
ac
ty.
Execution Time:
rsi
ive
0.002s
un
TestCase2: ias
t
lgo
ga
Input:
9@
Expected Output:
1
e1
cs
Output:
li.2
a
ep
4
de
Execution Time:
li V
pa
0.001s
e
De
You are required to implement a function findMaxCapacity(int arr[], int n, int k) that
takes an array representing the capacity of sections and returns the starting index of
the subarray of length k with the maximum sum. If there are multiple subarrays with
the same maximum sum, return the smallest starting index.
Input:The first line will contain two integers n and k (1 ≤ k ≤ n ≤ 10^6), representing the
size of the array and the length of the subarray.The second line will contain n space-
separated integers which represents the elements of the array arr[i] (-10^4 ≤ arr[i] ≤
10^4).
Output:Print a single integer, the starting index (0-based) of the subarray of length k
with the maximum sum.
)
.in
subarray is always less than or equal to n.The elements of the array can be both
ac
positive and negative.
ty.
rsi
Example:Consider the following array with n = 6 and k = 3:
ive
Input:6 32 1 -3 4 5 -6
un
ias
Step 1: Identify the subarray with the maximum sum
t
lgo
Subarray [4, 5, -6] starting at index 3 has the highest sum of 3.
ga
9@
Output:2
14
80
1
Concepts Included:
li.2
a
Language Used: C
m
er
li V
Source Code:
pa
e
#include <stdio.h>
De
int main() {
int n, k;
scanf("%d %d", &n, &k);
int arr[n];
for(int i = 0; i < n; i++) {
scanf("%d", &arr[i]);
}
int current_sum = 0;
for(int i = 0; i < k; i++) {
current_sum += arr[i];
}
int max_sum = current_sum;
int start_index = 0;
for(int i = k; i < n; i++) {
current_sum += arr[i] - arr[i - k];
if(current_sum > max_sum) {
max_sum = current_sum;
start_index = i - k + 1;
}
}
printf("%d\n", start_index);
return 0;
}
Compilation Details:
TestCase1:
)
.in
Input:
ac
ty.
< hidden >
rsi
ive
Expected Output:
un
< hidden >
iast
lgo
Output:
ga
2
9@
14
Execution Time:
e1
cs
0.001s
4s
li.2
a
TestCase2:
ep
de
Input:
a(
m
Expected Output:
pa
e
De
Output:
4
Problem Description:
You are given an n x m grid representing a matrix of integers. Your task is to find the
maximum sum possible by starting at the top-left corner of the matrix (i.e., cell (0, 0))
and moving to the bottom-right corner of the matrix (i.e., cell (n-1, m-1)). You can only
move either to the right or down at each step.
You need to implement this using array declarations and the array index operator to
access matrix elements.
)
Input:The first line contains two integers n and m (1 ≤ n, m ≤ 100), representing the
.in
dimensions of the matrix.The next n lines each contain m space-separated integers
ac
ty.
representing the matrix elements.
rsi
Output:Print a single integer, the maximum sum obtainable by following the path from
ive
the top-left to the bottom-right of the matrix.
un
ias
Sample Input:3 31 2 34 5 67 8 9
t
lgo
Sample Output:29
ga
9@
Concepts Included:
er
li V
Language Used: C
Source Code:
#include <stdio.h>
void getInputMatrix(int matrix[][100], int n, int m) {
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
scanf("%d", &matrix[i][j]);
}
}
}
int findMaxPathSum(int matrix[][100], int n, int m) {
int dp[100][100];
dp[0][0] = matrix[0][0];
for (int j = 1; j < m; j++) {
dp[0][j] = dp[0][j-1] + matrix[0][j];
}
for (int i = 1; i < n; i++) {
dp[i][0] = dp[i-1][0] + matrix[i][0];
}
for (int i = 1; i < n; i++) {
for (int j = 1; j < m; j++) {
dp[i][j] = matrix[i][j] + (dp[i-1][j] > dp[i][j-1] ? dp[i-1][j] : dp[i][j-1]);
}
}
return dp[n-1][m-1];
}
)
.in
int main() {
ac
int n, m;
ty.
scanf("%d %d", &n, &m);
rsi
int matrix[100][100];
ive
getInputMatrix(matrix, n, m);
un
int result = findMaxPathSum(matrix, n, m);
ias
printf("%d\n", result);
t
lgo
return 0;
}
ga
9@
14
Compilation Details:
180
e1
TestCase1:
cs
4s
Input:
ali.2
Expected Output:
a(
m
Output:
pa
e
29
De
TestCase2:
Input:
< hidden >
Expected Output:
< hidden >
Output:
68
)
.in
ac
You are working on a project where you need to manipulate a large array of integers
ty.
for data processing. One of the operations involves rotating the elements of the array
rsi
to the left or right by a given number of positions. The goal is to write a C program
ive
that performs this operation efficiently.
un
ias
You are required to implement the function rotateArray(int arr[], int n, int d, char dir)
that rotates the array arr[] of size n by d positions. The direction of rotation is
t
lgo
determined by the dir parameter, where 'L' indicates a left rotation and 'R' indicates a
ga
right rotation.
9@
The solution must include proper looping through the array elements to achieve the
14
80
rotation without using extra space for another array (in-place rotation).
1
e1
Input:The first line contains two integers n and d (1 ≤ d ≤ n ≤ 10^6), representing the
cs
size of the array and the number of positions to rotate.The second line will contain
4s
the n space-separated integers which basically represents the elements of the array
li.2
arr[i] (-10^4 ≤ arr[i] ≤ 10^4).The third line contains a single character dir which is either
a
Sample Input:5 21 2 3 4 5L
er
li V
Sample Output:3 4 5 1 2
pa
e
positions d will always be less than or equal to n.The elements of the array can be
both positive and negative integers.
Concepts Included:
gu 28 1st semester c programming
Language Used: C
Source Code:
#include <stdio.h>
void reverse(int arr[], int start, int end) {
while (start < end) {
int temp = arr[start];
arr[start] = arr[end];
arr[end] = temp;
start++;
end--;
)
.in
}
ac
}
ty.
void rotateArray(int arr[], int n, int d, char dir) {
rsi
if (dir == 'L') {
ive
d = d % n;
un
reverse(arr, 0, n - 1);
ias
reverse(arr, 0, n - d - 1);
t
lgo
reverse(arr, n - d, n - 1);
} else if (dir == 'R') {
ga
d = d % n;
9@
d = n - d;
14
reverse(arr, 0, n - 1);
80
reverse(arr, 0, n - d - 1);
1
e1
reverse(arr, n - d, n - 1);
cs
}
4s
}
li.2
int main() {
a
int n, d;
ep
char dir;
de
int arr[n];
m
er
scanf("%d", &arr[i]);
pa
}
e
rotateArray(arr, n, d, dir);
for (int i = 0; i < n; i++) {
printf("%d ", arr[i]);
}
printf("\n");
return 0;
}
Compilation Details:
TestCase1:
Input:
< hidden >
Expected Output:
< hidden >
Output:
34512
)
.in
TestCase2:
ac
ty.
Input:
rsi
ive
< hidden >
un
ias
Expected Output:
t
lgo
< hidden >
ga
9@
Output:
14
-4 -5 -6 -1 -2 -3
80
1
Execution Time:
4s
li.2
0.001s
a
ep
de
a(
Allocated Arrays
li V
pa
Problem Description:
e
De
You are working for a logistics company that manages inventory for different types of
products stored in a warehouse. Each product has a unique identifier, a name, a
quantity, and a price. You need to write a C program to store and manage the
inventory information dynamically using heap-allocated arrays.
Your task:
Add Product: Add a new product to the inventory.Update Product Quantity: Update the
quantity of a specific product.Calculate Total Inventory Value: Calculate the total
value of the inventory.Remove Product: Remove a product from the inventory.List All
Products: List all products in the inventory.You must use dynamic memory allocation
to store the product information and ensure that the program efficiently handles
memory reallocation as products are added or removed.
Input format:
The first input is an integer N, which represents the number of operations to be
performed.Each of the following N lines represents an operation. The operations can
be one of the following:ADD id name quantity priceUPDATE id quantityREMOVE
idTOTALLIST
Output format:
For ADD, no output is required.For UPDATE, print "Product updated successfully" if the
product exists, otherwise print "Product not found".For REMOVE, print "Product
removed successfully" if the product exists, otherwise print "Product not found".For
TOTAL, print the total inventory value as a float rounded to 2 decimal places.For LIST,
print all products in the format: id name quantity price.
)
.in
15TOTALREMOVE 102LIST
ac
ty.
Sample Output:Product updated successfully9999.35Product removed
rsi
successfully101 "Laptop" 15 599.99
ive
Constraints:
un
ias
1 <= N <= 10000 <= quantity <= 100000.0 <= price <= 100000.0The length of the
t
lgo
product name will not exceed 50 characters.All product identifiers will be unique and
are positive integers.You must use dynamic memory allocation (malloc, realloc, free)
ga
Explanation:
180
quantity of the Laptop is updated to 15.The total inventory value is calculated as (15 *
li.2
Concepts Included:
e
De
Language Used: C
Source Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct {
int id;
char name[51];
int quantity;
float price;
} Product;
void addProduct(Product** inventory, int* size, int* capacity, int id, const char* name,
int
quantity, float price) {
if (*size == *capacity) {
*capacity *= 2;
*inventory = realloc(*inventory, (*capacity) * sizeof(Product));
}
(*inventory)[*size].id = id;
strcpy((*inventory)[*size].name, name);
(*inventory)[*size].quantity = quantity;
(*inventory)[*size].price = price;
(*size)++;
}
)
.in
void updateProduct(Product* inventory, int size, int id, int quantity) {
ac
for (int i = 0; i < size; i++) {
ty.
if (inventory[i].id == id) {
rsi
inventory[i].quantity = quantity;
ive
printf("Product updated successfully\n");
un
return;
ias
}
t
lgo
}
printf("Product not found\n");
ga
}
9@
if ((*inventory)[i].id == id) {
1
e1
}
li.2
(*size)--;
a
return;
de
}
a(
}
m
er
}
pa
)
.in
} else if (strcmp(operation, "REMOVE") == 0) {
ac
int id;
ty.
scanf("%d", &id);
rsi
removeProduct(&inventory, &size, id);
ive
} else if (strcmp(operation, "TOTAL") == 0) {
un
calculateTotalValue(inventory, size);
ias
} else if (strcmp(operation, "LIST") == 0) {
t
lgo
listAllProducts(inventory, size);
}
ga
}
9@
free(inventory);
14
return 0;
80
}
1
e1
cs
Compilation Details:
4s
li.2
a
TestCase1:
ep
de
Input:
a(
m
Expected Output:
pa
e
De
Output:
6999.40
Product updated successfully
101 "Laptop" 10 599.99
102 "Mouse" 45 19.99
Expected Output:
< hidden >
Output:
Product not found
Product removed successfully
)
.in
Execution Time:
ac
ty.
0.002s
rsi
ive
un
ias
33. Reversing Words in a Sentence Stored in a Dynamic
t
ArrayProblem Statement:You are required to write a program that
lgo
for this sentence, and then reverses the order of the words in the
14
sentence. The reversal should happen at the word level, not the
80
output.
cs
4s
Description:Your task is to handle a string input dynamically using heap memory. The
li.2
input string will contain multiple words separated by spaces. You need to reverse the
a
order of the words in the sentence while keeping the characters within each word
ep
intact. For example, the sentence "Hello World" should become "World Hello". Be
de
careful with the memory allocation and deallocation to avoid memory leaks.
a(
m
Input Format:
er
li V
A single line of text containing a sentence. The sentence can have multiple words
pa
A single line of text containing the sentence with the order of words reversed.
Concepts Included:
gu 28 1st semester c programming
Language Used: C
Source Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void reverseWords(char *sentence) {
char *words[100];
int wordCount = 0;
char *token = strtok(sentence, " ");
while (token != NULL) {
words[wordCount++] = token;
token = strtok(NULL, " ");
)
}
.in
for (int i = wordCount - 1; i >= 0; i--) {
ac
printf("%s", words[i]);
ty.
rsi
if (i != 0) {
ive
printf(" ");
}
un
ias
}
printf("\n"); t
lgo
}
ga
int main() {
9@
if (sentence == NULL) {
80
return 1;
e1
}
cs
reverseWords(sentence);
a
ep
free(sentence);
de
return 0;
a(
}
m
er
li V
Compilation Details:
pa
e
De
TestCase1:
Input:
< hidden >
Expected Output:
< hidden >
Output:
C in management Memory
TestCase2:
Input:
< hidden >
Expected Output:
< hidden >
Output:
)
.in
fun is C Learning
ac
ty.
Compilation Status: Passed
rsi
ive
Execution Time:
un
ias
0.001s
t
lgo
ga
and then counts and displays the frequency of each vowel (a, e, i, o,
e1
cs
Description:You are tasked with managing multiple strings using a dynamic array of
a
pointers. Each string will be stored in the heap. After storing the strings, your program
ep
should calculate the frequency of each vowel in all the strings combined. Consider
de
both uppercase and lowercase vowels, but treat them as the same (e.g., 'A' and 'a'
a(
Input Format:
li V
pa
The first line contains an integer n, the number of strings.The following n lines each
e
De
Print the frequency of each vowel (a, e, i, o, u) across all the strings.
Sample Input:3HelloWorldEducation
Sample Output:a: 1, e: 2, i: 1, o: 3, u: 1
Concepts Included:
gu 28 1st semester c programming
Language Used: C
Source Code:
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
int main() {
int n;
scanf("%d", &n);
getchar();
char **strings = (char **)malloc(n * sizeof(char *));
if (strings == NULL) {
printf("Memory allocation failed\n");
)
return 1;
.in
}
ac
for (int i = 0; i < n; i++) {
ty.
rsi
strings[i] = (char *)malloc(100 * sizeof(char));
ive
if (strings[i] == NULL) {
printf("Memory allocation failed\n");
un
ias
return 1;
} t
lgo
fgets(strings[i], 100, stdin);
ga
}
14
char c = tolower(strings[i][j]);
cs
if (c == 'a') vowels[0]++;
4s
}
m
}
er
printf("a: %d, e: %d, i: %d, o: %d, u: %d\n", vowels[0], vowels[1], vowels[2], vowels[3],
li V
vowels[4]);
pa
free(strings[i]);
}
free(strings);
return 0;
}
Compilation Details:
TestCase1:
Input:
< hidden >
Expected Output:
< hidden >
Output:
a: 1, e: 2, i: 1, o: 3, u: 1
TestCase2:
)
.in
Input:
ac
ty.
< hidden >
rsi
ive
Expected Output:
un
ias
< hidden >
t
lgo
Output:
ga
9@
a: 3, e: 1, i: 1, o: 1, u: 1
14
Execution Time:
cs
4s
0.001s
li.2
a
ep
it. The program should then count the frequency of each character
pa
the count.
Description:Your task is to handle a paragraph input dynamically using heap memory.
The input paragraph may contain multiple sentences, spaces, and punctuation marks.
You need to count the frequency of each character (ignoring case and excluding
spaces/punctuation) and then print the frequencies in descending order. The
characters with the same frequency should be printed in alphabetical order.
Input Format:
Sample Output:g: 2i: 2m: 2n: 2r: 2a: 1c: 1f: 1o: 1p: 1s: 1u: 1
Concepts Included:
gu 28 1st semester c programming
Language Used: C
Source Code:
)
.in
ac
#include <stdio.h>
ty.
#include <stdlib.h>
rsi
#include <ctype.h>
ive
#include <string.h>
un
#define MAX_CHAR 26
ias
typedef struct {
t
lgo
char character;
ga
int frequency;
9@
} CharFreq;
void countFrequency(char *str, CharFreq **freq, int *size) {
14
char c = tolower(str[i]);
cs
if (isalpha(c)) {
4s
count[c - 'a']++;
li.2
}
a
ep
}
de
*size = 0;
a(
if (count[i] > 0) {
er
(*size)++;
li V
}
pa
}
e
De
)
.in
int size = 0;
ac
countFrequency(input, &freq, &size);
ty.
qsort(freq, size, sizeof(CharFreq), compare);
rsi
for (int i = 0; i < size; i++) {
ive
printf("%c: %d\n", freq[i].character, freq[i].frequency);
un
}
ias
free(input);
t
lgo
free(freq);
return 0;}
ga
9@
14
Compilation Details:
80
1
e1
TestCase1:
cs
4s
Input:
li.2
a
Expected Output:
a(
m
Output:
pa
e
g: 2
De
i: 2
m: 2
n: 2
r: 2
a: 1
c: 1
f: 1
o: 1
p: 1
s: 1
u: 1
TestCase2:
Input:
< hidden >
Expected Output:
< hidden >
Output:
)
.in
a: 4
ac
t: 4
ty.
r: 3
rsi
s: 3
ive
d: 2
un
u: 2
ias
c: 1
t
lgo
e: 1
ga
g: 1
9@
h: 1
i: 1
14
l: 1
80
m: 1
1
e1
n: 1
cs
o: 1
4s
li.2
Execution Time:
de
a(
0.001s
m
er
li V
pa
user, dynamically allocates memory for the matrix, and rotates the
matrix by 90 degrees clockwise. The rotated matrix should then be
printed as the output.
Description:Your task is to handle the matrix input dynamically using heap memory.
The input matrix will be square (n x n), and you need to rotate the matrix by 90
degrees clockwise. This operation involves transposing the matrix and then reversing
the rows.
Input Format:
The first line contains an integer n, the size of the matrix (n x n).The next n lines
contain n integers each, representing the matrix.Output Format:
The output should be the rotated matrix, with each row printed on a new line.
Sample Input:31 2 34 5 67 8 9
Sample Output:7 4 1 8 5 2 9 6 3
Concepts Included:
gu 28 1st semester c programming
Language Used: C
)
.in
ac
Source Code:
ty.
rsi
#include <stdio.h>
ive
#include <stdlib.h>
un
void rotateMatrix(int **matrix, int n) {
ias
for (int i = 0; i < n; i++) {
t
lgo
for (int j = i; j < n; j++) {
int temp = matrix[i][j];
ga
matrix[i][j] = matrix[j][i];
9@
matrix[j][i] = temp;
14
}
80
}
1
e1
matrix[i][n - j - 1] = temp;
ep
}
de
}
a(
}
m
er
int main() {
li V
int n;
pa
scanf("%d", &n);
e
Compilation Details:
TestCase1:
Input:
)
.in
< hidden >
ac
Expected Output:
ty.
rsi
< hidden >
ive
un
Output:
iast
lgo
741
852
ga
963
9@
14
Execution Time:
e1
cs
0.002s
4s
li.2
a
TestCase2:
ep
de
Input:
a(
m
Expected Output:
epa
De
Output:
31
42
Input Format:
The first line contains a string stored in a character array arr (length ≤ 100).The
second line contains a character replacement that will replace the vowels in the
)
.in
string.Output Format:
ac
ty.
Output the modified string after replacing the vowels.
rsi
ive
Sample Input:hello_world\0programming*
un
ias
Sample Output:h*ll*_w*rld\0pr*gr*mm*ng
t
lgo
ga
Concepts Included:
80
1
e1
Language Used: C
a
ep
de
Source Code:
a(
#include <stdio.h>
m
er
#include <ctype.h>
li V
char c = arr[i];
De
Compilation Details:
TestCase1:
Input:
< hidden >
Expected Output:
< hidden >
Output:
)
.in
ac
h*ll*_w*rld\0pr*gr*mm*ng
ty.
rsi
ive
Compilation Status: Passed
un
ias
Execution Time:
t
lgo
0.001s
ga
9@
TestCase2:
14
80
Input:
1
e1
Expected Output:
li.2
a
ep
Output:
a(
m
B###t#f#l_C#d#\0
er
li V
pa
Execution Time:
0.001s
Input Format:
The input is a single line containing a string stored in a character array arr (length ≤
100).Output Format:
Sample Output:2
)
.in
ac
Completion Status: Completed
ty.
rsi
Concepts Included:
ive
un
gu 28 1st semester c programming
ias
t
lgo
Language Used: C
ga
9@
Source Code:
14
80
#include <stdio.h>
1
e1
int count = 0, i = 0;
4s
int in_word = 0;
li.2
in_word = 1;
de
count++;
a(
in_word = 0;
li V
}
pa
i++;
e
}
De
return count;
}
int main() {
char arr[101];
fgets(arr, 101, stdin);
int word_count = count_words(arr);
printf("%d\n", word_count);
return 0;
}
Compilation Details:
TestCase1:
Input:
< hidden >
Expected Output:
< hidden >
Output:
2
)
Execution Time:
.in
ac
0.001s
ty.
rsi
ive
TestCase2:
un
ias
Input:
t
lgo
< hidden >
ga
9@
Expected Output:
14
Output:
cs
4s
4
li.2
Execution Time:
a(
m
0.001s
er
li V
pa
Sample Input:54 7 2 9 6
Sample Output:28 0 18 0 6
Concepts Included:
gu 28 1st semester c programming
)
.in
ac
Language Used: C
ty.
rsi
ive
Source Code:
un
ias
#include <stdio.h>
t
lgo
void manipulate_array(int arr[], int n) {
for (int i = 0; i < n - 1; i++) {
ga
if (*(arr + i) % 2 == 0) {
9@
} else {
80
}
cs
}
4s
}
li.2
int main() {
a
int n;
ep
scanf("%d", &n);
de
int arr[n];
a(
scanf("%d", &arr[i]);
li V
}
pa
manipulate_array(arr, n);
e
Compilation Details:
TestCase1:
Input:
< hidden >
Expected Output:
< hidden >
Output:
28 0 18 0 6
TestCase2:
)
.in
Input:
ac
ty.
< hidden >
rsi
ive
Expected Output:
un
ias
< hidden >
t
lgo
Output:
ga
9@
Execution Time:
cs
4s
0.002s
li.2
a
ep
Reverse each string.Swap the first and last string in the list.Print the modified
e
De
list.Description:The program should first read the number of strings and then the
strings themselves. Use a pointer-to-pointer (char **) to manage the list of strings.
After reversing each string, swap the first and last strings in the list. Finally, print the
modified list of strings. The implementation should handle variable string lengths and
ensure memory safety by properly allocating and freeing memory.
Input Format:
The first line contains an integer n, the number of strings.The next n lines each
contain a single string.Output Format:
Sample Input:3algorithmcodelanguage
Sample Output:egaugnaledocmhtirogla
Completion Status: Completed
Concepts Included:
gu 28 1st semester c programming
Language Used: C
Source Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void reverseString(char *str) {
)
.in
int start = 0, end = strlen(str) - 1;
ac
while (start < end) {
ty.
char temp = str[start];
rsi
str[start] = str[end];
ive
str[end] = temp;
un
start++;
end--;
iast
lgo
}
ga
}
9@
int main() {
14
int n;
80
scanf("%d", &n);
1
scanf("%s", arr[i]);
li.2
}
a
ep
reverseString(arr[i]);
a(
}
m
arr[n - 1] = temp;
pa
printf("%s\n", arr[i]);
}
for (int i = 0; i < n; i++) {
free(arr[i]);
}
free(arr);
return 0;
}
Compilation Details:
TestCase1:
Input:
< hidden >
Expected Output:
< hidden >
Output:
egaugnal
edoc
mhtirogla
)
Execution Time:
.in
ac
0.001s
ty.
rsi
ive
TestCase2:
un
ias
Input:
t
lgo
< hidden >
ga
9@
Expected Output:
14
80
Output:
cs
4s
edocC
li.2
avaJ
a
nohtyP
ep
C
de
a(
Execution Time:
li V
pa
0.001s
e
De
Concepts Included:
gu 28 1st semester c programming
Language Used: C
)
.in
Source Code:
ac
ty.
#include <stdio.h>
rsi
#include <string.h>
ive
void reorderString(char *s) {
un
int len = strlen(s);
ias
char result[100]; // Assuming the input will not exceed 100 characters
t
lgo
int resultIndex = 0;
ga
}
80
result[resultIndex++] = s[i];
4s
}
li.2
result[resultIndex] = '\0';
de
a(
printf("%s\n", result);
er
}
li V
int main() {
pa
char s[100];
e
De
scanf("%s", s);
reorderString(s);
return 0;
}
Compilation Details:
TestCase1:
Input:
< hidden >
Expected Output:
< hidden >
Output:
bdfeca
TestCase2:
Input:
)
.in
< hidden >
ac
ty.
Expected Output:
rsi
ive
< hidden >
un
ias
Output:
t
lgo
pniaeo
ga
9@
Execution Time:
80
1
e1
0.002s
cs
4s
li.2
and removes every third character from the string using pointer
a(
so on). You should utilize pointer arithmetic to traverse and modify the string. Ensure
De
that the string is null-terminated after modification. The program must handle strings
of various lengths and should dynamically allocate memory as needed.
Input Format:
Sample Input:abcdefghijklmnopq
Sample Output:abdeghjkmnpq
Language Used: C
Source Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void removeEveryThirdChar(char *str) {
int len = strlen(str);
int count = 0;
)
.in
for (int i = 2; i < len; i++) {
ac
str[i - count] = str[i];
ty.
if ((i + 1) % 3 == 0) {
rsi
count++;
ive
}
un
}
ias
str[len - count] = '\0';
} t
lgo
int main() {
ga
char str[101];
9@
removeEveryThirdChar(str);
1
e1
printf("%s\n", str);
cs
return 0;
4s
}
li.2
a
ep
Compilation Details:
de
a(
TestCase1:
m
er
li V
Input:
pa
Expected Output:
< hidden >
Output:
abdeghjkmnpq
Expected Output:
< hidden >
Output:
OpnAismain
)
Execution Time:
.in
ac
0.001s
ty.
rsi
ive
un
43. Understanding L-Value ModificationProblem Statement:Write a
ias
C program that demonstrates the concept of L-value by creating an
t
lgo
integer variable, assigning its address to a pointer, and modifying
ga
its value using the pointer. Then, dynamically allocate memory for
9@
another integer using malloc and modify its value, finally printing
14
both integers.
80
1
e1
a value. Next, assign the address of this variable to a pointer and use the pointer to
4s
modify the variable's value. The program should then dynamically allocate memory in
li.2
the heap for another integer, modify its value using a pointer, and print both the
a
original integer (modified through the pointer) and the dynamically allocated integer.
ep
de
Input Format:
a(
m
Two integers: The first integer is the initial value for the integer variable, and the
er
Format:
pa
e
Print the modified value of the original integer.Print the value stored in the
De
Sample Input:10 25
Concepts Included:
gu 28 1st semester c programming
Language Used: C
Source Code:
#include <stdio.h>
#include <stdlib.h>
int main() {
int original;
int *ptr1;
int *heapPtr;
int initialValue, heapValue;
scanf("%d %d", &initialValue, &heapValue);
original = initialValue;
ptr1 = &original;
)
*ptr1 += 5;
.in
heapPtr = (int *)malloc(sizeof(int));
ac
if (heapPtr == NULL) {
ty.
rsi
return 1;
ive
}
*heapPtr = heapValue;
un
ias
printf("Original Integer: %d\n", original);
printf("Heap Integer: %d\n", *heapPtr); t
lgo
free(heapPtr);
ga
return 0;
9@
}
14
80
Compilation Details:
1
e1
cs
TestCase1:
4s
li.2
Input:
a
ep
de
Expected Output:
m
er
li V
Output:
e
De
Original Integer: 5
Heap Integer: 100
TestCase2:
Input:
< hidden >
Expected Output:
< hidden >
Output:
Original Integer: -5
Heap Integer: 50
)
.in
44. Dynamic Memory Allocation and L-Value ExpressionsProblem
ac
Statement:Create a C program that dynamically allocates memory
ty.
rsi
for an array of integers on the heap. The program should read the
ive
array's size and elements from the user. Then, calculate the sum of
un
all even-indexed elements and store the result in the first element of
the array using L-value expressions. iast
lgo
ga
Description:The program should prompt the user to enter the number of elements
9@
and then read these elements into a dynamically allocated array. It should then
compute the sum of all elements located at even indices (0, 2, 4, etc.) and store
14
80
theresult in the first element of the array using L-value expressions. Finally, the
1
Output Format:Print the modified array, with the first element now holding the sum of
ep
Sample Input:51 2 3 4 5
m
er
Sample Output:9 2 3 4 5
li V
pa
e
De
Concepts Included:
gu 28 1st semester c programming
Language Used: C
Source Code:
#include <stdio.h>
#include <stdlib.h>
int main() {
int n;
scanf("%d", &n);
int *arr = (int *)malloc(n * sizeof(int));
for (int i = 0; i < n; i++) {
scanf("%d", &arr[i]);
}
int sum = 0;
for (int i = 0; i < n; i += 2) {
sum += arr[i];
}
arr[0] = sum;
for (int i = 0; i < n; i++) {
printf("%d ", arr[i]);
}
free(arr);
)
.in
return 0;
ac
}
ty.
rsi
ive
Compilation Details:
un
ias
TestCase1:
t
lgo
Input:
ga
9@
Expected Output:
1
e1
Output:
ali.2
92345
ep
de
Execution Time:
er
li V
0.001s
pa
e
De
TestCase2:
Input:
< hidden >
Expected Output:
< hidden >
Output:
8357
)
.in
ac
Description:The program should:
ty.
Dynamically allocate memory for an array to store integers.Copy the contents of the
rsi
ive
original array into a new, larger array.Print both the original and the new array.Ensure
proper memory management by freeing all dynamically allocated memory.Input
un
Format:
iast
lgo
An integer n, the number of elements in the array.n integers to populate the
ga
array.Output Format:
9@
Sample Input:31 2 3
1
e1
Concepts Included:
a(
m
er
Language Used: C
e
De
Source Code:
#include <stdio.h>
#include <stdlib.h>
int main() {
int n;
scanf("%d", &n);
int *original = (int *)malloc(n * sizeof(int));
if (original == NULL) {
printf("Memory allocation failed\n");
return 1;
}
for (int i = 0; i < n; i++) {
scanf("%d", &original[i]);
}
int *copied = (int *)malloc(2 * n * sizeof(int));
if (copied == NULL) {
printf("Memory allocation failed\n");
free(original);
return 1;
}
for (int i = 0; i < n; i++) {
copied[i] = original[i];
}
for (int i = n; i < 2 * n; i++) {
copied[i] = 0;
}
printf("Original array: ");
)
.in
for (int i = 0; i < n; i++) {
ac
printf("%d ", original[i]);
ty.
}
rsi
printf("\n");
ive
printf("Copied array: ");
un
for (int i = 0; i < 2 * n; i++) {
ias
printf("%d ", copied[i]);
t
lgo
}
printf("\n");
ga
free(original);
9@
free(copied);
14
return 0;
80
}
1
e1
cs
Compilation Details:
4s
li.2
a
TestCase1:
ep
de
Input:
a(
m
Expected Output:
epa
De
Output:
Original array: 1 2 3
Copied array: 1 2 3 0 0 0
TestCase2:
Input:
< hidden >
Expected Output:
< hidden >
Output:
Original array: 4 5 6 7
Copied array: 4 5 6 7 0 0 0 0
)
.in
0.001s
ac
ty.
rsi
ive
46. Pointer Arithmetic and Dynamic Array ModificationProblem
un
Statement:Write a C program that uses pointers to manipulate a
dynamically allocated array. The program should: iast
lgo
ga
Allocate memory for an array of n integers.Initialize the array with values such that
9@
each element is the square of its index.Create a function that takes a pointer to the
array and performs the following:Increase each element by the value of the next
14
element, except for the last element.Swap the first and last elements of the
80
array. Ensure that you use the address-of operator (&) to pass pointers to functions
cs
and the value-at operator (*) to manipulate array elements. Handle memory allocation
4s
Input Format:
ep
de
Sample Input:5
pa
Sample Output:16 5 13 25 1
e
De
Concepts Included:
gu 28 1st semester c programming
Language Used: C
Source Code:
#include <stdio.h>
#include <stdlib.h>
void modifyArray(int *arr, int n) {
for (int i = 0; i < n - 1; i++) {
arr[i] += arr[i + 1];
}
int temp = arr[0];
arr[0] = arr[n - 1];
arr[n - 1] = temp;
}
int main() {
int n;
scanf("%d", &n);
int *arr = (int *)malloc(n * sizeof(int));
for (int i = 0; i < n; i++) {
arr[i] = i * i;
)
.in
}
ac
modifyArray(arr, n);
ty.
for (int i = 0; i < n; i++) {
rsi
printf("%d ", arr[i]);
ive
}
un
printf("\n");
ias
free(arr);
t
lgo
return 0;
}
ga
9@
14
Compilation Details:
80
1
e1
TestCase1:
cs
4s
Input:
ali.2
Expected Output:
a(
m
Output:
pa
e
16 5 13 25 1
De
TestCase2:
Input:
< hidden >
Expected Output:
< hidden >
Output:
451
)
2D array (matrix) using pointers to pointers. The program should:
.in
ac
ty.
Allocate memory for a matrix of size m x n.Initialize the matrix such that each
rsi
element matrix[i][j] is the product of its indices (i * j).Create a function that takes a
ive
pointer to the matrix and:Transposes the matrix (swap rows and columns).Prints the
un
transposed matrix.Description:Use pointer-to-pointer (int **) to manage the 2D array.
ias
Implement the transpose function by correctly accessing and modifying the matrix
elements using the value-at (*) and address-of (&) operators. t
lgo
ga
Input Format:
9@
Two integers m and n, indicating the number of rows and columns in the
14
matrix.Output Format:
80
1
e1
Sample Input:2 3
4s
li.2
Sample Output:0 0 0 1 0 2
a
ep
de
a(
Concepts Included:
pa
e
Language Used: C
Source Code:
#include <stdio.h>
#include <stdlib.h>
void transposeMatrix(int **matrix, int m, int n) {
int **transposed = (int **)malloc(n * sizeof(int *));
for (int i = 0; i < n; i++) {
transposed[i] = (int *)malloc(m * sizeof(int));
}
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
transposed[j][i] = matrix[i][j];
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
printf("%d ", transposed[i][j]);
}
printf("\n");
}
for (int i = 0; i < n; i++) {
free(transposed[i]);
}
free(transposed);
}
)
.in
int main() {
ac
int m, n;
ty.
scanf("%d %d", &m, &n);
rsi
int **matrix = (int **)malloc(m * sizeof(int *));
ive
for (int i = 0; i < m; i++) {
un
matrix[i] = (int *)malloc(n * sizeof(int));
ias
}
t
lgo
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
ga
matrix[i][j] = i * j;
9@
}
14
}
80
transposeMatrix(matrix, m, n);
1
e1
free(matrix[i]);
4s
}
li.2
free(matrix);
a
return 0;
ep
}
de
a(
m
Compilation Details:
er
li V
pa
TestCase1:
e
De
Input:
< hidden >
Expected Output:
< hidden >
Output:
00
01
02
TestCase2:
Input:
< hidden >
Expected Output:
< hidden >
Output:
)
.in
000
ac
012
ty.
rsi
Compilation Status: Passed
ive
un
Execution Time:
0.001s iast
lgo
ga
9@
Define an array of integers and use a pointer to traverse and modify it.Use a function
4s
to modify the array by passing the array name (which is a pointer) and demonstrate
li.2
question examines how arrays (which are L-values) and pointers interact. You will
de
demonstrate how changes made through a pointer affect the original array and how
a(
Input Format:
li V
Sample Input:4 1 2 3 4
Concepts Included:
gu 28 1st semester c programming
Language Used: C
Source Code:
#include <stdio.h>
void modify_array(int *arr, int n) {
for (int i = 0; i < n; i++) {
arr[i] += 4;
}
}
int main() {
int n;
scanf("%d", &n);
int arr[n];
for (int i = 0; i < n; i++) {
scanf("%d", &arr[i]);
}
)
.in
printf("Array before modification:\n");
ac
for (int i = 0; i < n; i++) {
ty.
printf("%d ", arr[i]);
rsi
}
ive
printf("\n");
un
modify_array(arr, n);
ias
printf("Array after modification:\n");
t
lgo
for (int i = 0; i < n; i++) {
printf("%d ", arr[i]);
ga
}
9@
printf("\n");
14
return 0;
80
}
1
e1
cs
Compilation Details:
4s
li.2
a
TestCase1:
ep
de
Input:
a(
m
Expected Output:
pa
e
De
Output:
Array before modification:
1234
Array after modification:
5678
Expected Output:
< hidden >
Output:
Array before modification:
71234
Array after modification:
11 5 6 7 8
)
.in
ac
Compilation Status: Passed
ty.
rsi
Execution Time:
ive
0.001s
un
iast
lgo
49. Matrix Multiplication with Dynamic AllocationProblem
ga
Statement:
9@
14
Write a program that dynamically allocates memory for two matrices, performs
80
matrix multiplication, and then frees the allocated memory. The matrices' sizes
1
e1
should be taken from user input, and you must handle errors such as mismatched
cs
dimensions.
4s
Description:
li.2
a
ep
Dynamically allocate memory for two matrices based on user input.Perform matrix
de
dimensions.Input Format:
er
li V
The dimensions of the first matrix R1 x C1.The dimensions of the second matrix R2 x
pa
matrices.Output Format:
De
Sample Input:2 33 21 2 34 5 67 89 10
Sample Output:25 28 73 82
Concepts Included:
gu 28 1st semester c programming
Language Used: C
Source Code:
#include <stdio.h>
#include <stdlib.h>
void multiplyMatrices(int **matrix1, int **matrix2, int **result, int R1, int C1, int R2, int
C2) {
for (int i = 0; i < R1; i++) {
for (int j = 0; j < C2; j++) {
result[i][j] = 0;
for (int k = 0; k < C1; k++) {
result[i][j] += matrix1[i][k] * matrix2[k][j];
}
)
}
.in
}
ac
}
ty.
rsi
int main() {
ive
int R1, C1, R2, C2;
scanf("%d %d", &R1, &C1);
un
ias
scanf("%d %d", &R2, &C2);
if (C1 != R2) { t
lgo
printf("Matrix multiplication is not possible due to incompatible dimensions.\n");
ga
return 1;
9@
}
14
}
cs
}
de
}
li V
scanf("%d", &matrix1[i][j]);
}
}
for (int i = 0; i < R2; i++) {
for (int j = 0; j < C2; j++) {
scanf("%d", &matrix2[i][j]);
}
}
multiplyMatrices(matrix1, matrix2, result, R1, C1, R2, C2);
for (int i = 0; i < R1; i++) {
for (int j = 0; j < C2; j++) {
printf("%d ", result[i][j]);
}
printf("\n");
}
for (int i = 0; i < R1; i++) {
free(matrix1[i]);
}
free(matrix1);
for (int i = 0; i < R2; i++) {
free(matrix2[i]);
}
free(matrix2);
for (int i = 0; i < R1; i++) {
free(result[i]);
}
free(result);
return 0;
}
)
.in
ac
Compilation Details:
ty.
rsi
ive
TestCase1:
un
ias
Input:
t
lgo
< hidden >
ga
9@
Expected Output:
14
80
Output:
cs
4s
25 28
li.2
73 82
a
ep
Execution Time:
m
er
0.001s
li V
e pa
TestCase2:
De
Input:
< hidden >
Expected Output:
< hidden >
Output:
27 30 33
61 68 75
95 106 117
Compilation Status: Passed
Execution Time:
0.001s
Description:
)
.in
Implement a circular buffer that can grow and shrink dynamically.Handle cases where
ac
the buffer needs resizing using realloc.Properly manage memory using malloc, calloc,
ty.
rsi
realloc, and free.Input Format:
ive
An integer n indicating the number of operations.For each operation, you will
un
receive:An operation type (ADD, REMOVE, RESIZE).Depending on the operation,
ias
additional parameters such as the value to add, or the new size for resizing.Output
t
lgo
Format:
ga
Sample Output:5 5 10 5 10 5 10 15 10 15 10 15 20
e1
cs
4s
Concepts Included:
de
a(
Language Used: C
pa
e
De
Source Code:
#include <stdio.h>
#include <stdlib.h>
typedef struct {
int *buffer;
int size;
int front;
int rear;
int count;
} CircularBuffer;
void initBuffer(CircularBuffer *cb, int size) {
cb->size = size;
cb->buffer = (int *)malloc(size * sizeof(int));
cb->front = 0;
cb->rear = 0;
cb->count = 0;
}
void freeBuffer(CircularBuffer *cb) {
free(cb->buffer);
}
int isFull(CircularBuffer *cb) {
return cb->count == cb->size;
}
int isEmpty(CircularBuffer *cb) {
return cb->count == 0;
}
void addElement(CircularBuffer *cb, int element) {
if (isFull(cb)) {
)
.in
printf("Buffer is full. Unable to add element.\n");
ac
return;
ty.
}
rsi
cb->buffer[cb->rear] = element;
ive
cb->rear = (cb->rear + 1) % cb->size;
un
cb->count++;
ias
}
t
lgo
void removeElement(CircularBuffer *cb) {
if (isEmpty(cb)) {
ga
return;
14
}
80
cb->count--;
cs
}
4s
int i, j;
ep
newBuffer[j] = cb->buffer[i];
a(
i = (i + 1) % cb->size;
m
er
}
li V
free(cb->buffer);
pa
cb->buffer = newBuffer;
e
cb->size = newSize;
De
cb->front = 0;
cb->rear = cb->count;
}
void printBuffer(CircularBuffer *cb) {
if (isEmpty(cb)) {
printf("Buffer is empty.\n");
return;
}
int i = cb->front;
for (int j = 0; j < cb->count; j++) {
printf("%d ", cb->buffer[i]);
i = (i + 1) % cb->size;
}
printf("\n");
}
int main() {
int n, newSize, value;
char operation[10];
scanf("%d", &n);
CircularBuffer cb;
initBuffer(&cb, 10);
for (int i = 0; i < n; i++) {
scanf("%s", operation);
if (strcmp(operation, "ADD") == 0) {
scanf("%d", &value);
addElement(&cb, value);
} else if (strcmp(operation, "REMOVE") == 0) {
removeElement(&cb);
} else if (strcmp(operation, "RESIZE") == 0) {
)
.in
scanf("%d", &newSize);
ac
resizeBuffer(&cb, newSize);
ty.
}
rsi
printBuffer(&cb);
ive
}
un
freeBuffer(&cb);
ias
return 0;
t
lgo
}
ga
9@
Compilation Details:
14
80
TestCase1:
1
e1
cs
Input:
4s
li.2
Expected Output:
de
a(
Output:
li V
pa
5
e
5 10
De
5 10
5 10 15
10 15
10 15 20
TestCase2:
Input:
< hidden >
Expected Output:
< hidden >
Output:
1
12
12
2
)
.in
ac
0.001s
ty.
rsi
ive
51. Dynamic Sparse Matrix RepresentationQuestion: Implement a
un
dynamic sparse matrix using linked lists. The matrix should support
ias
insertion, deletion, and retrieval of elements at specified positions.
t
lgo
Each non-zero element should be stored with its row, column, and
ga
value.
9@
14
Description: Create a sparse matrix where only non-zero elements are stored to save
80
column.Input Format:
4s
li.2
The first line contains an integer n, the number of operations.Each of the next n lines
a
ep
For RETRIEVE, output the value of the element at the specified position or "0" if the
m
er
Sample Output:50
Concepts Included:
gu 28 1st semester c programming
Language Used: C
Source Code:
#include <stdio.h>
#include <stdlib.h>
typedef struct Node {
int row, col, value;
struct Node *next;
} Node;
Node *head = NULL;
void insert(int row, int col, int value) {
Node *newNode = (Node *)malloc(sizeof(Node));
newNode->row = row;
newNode->col = col;
newNode->value = value;
newNode->next = NULL;
if (!head) {
head = newNode;
)
.in
return;
ac
}
ty.
Node *temp = head;
rsi
while (temp->next) {
ive
if (temp->row == row && temp->col == col) {
un
temp->value = value;
ias
free(newNode);
t
lgo
return;
}
ga
temp = temp->next;
9@
}
14
temp->next = newNode;
80
}
1
e1
while (temp) {
li.2
if (prev) {
ep
prev->next = temp->next;
de
} else {
a(
head = temp->next;
m
er
}
li V
free(temp);
pa
return;
e
}
De
prev = temp;
temp = temp->next;
}
}
int retrieve(int row, int col) {
Node *temp = head;
while (temp) {
if (temp->row == row && temp->col == col) {
return temp->value;
}
temp = temp->next;
}
return 0;
}
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
char operation[10];
int row, col, value;
scanf("%s", operation);
if (operation[0] == 'I') {
scanf("%d %d %d", &row, &col, &value);
insert(row, col, value);
} else if (operation[0] == 'D') {
scanf("%d %d", &row, &col);
delete(row, col);
} else if (operation[0] == 'R') {
scanf("%d %d", &row, &col);
)
.in
printf("%d\n", retrieve(row, col));
ac
}
ty.
}
rsi
return 0;
ive
}
un
Compilation Details: iast
lgo
ga
TestCase1:
9@
14
Input:
80
1
e1
Expected Output:
4s
li.2
Output:
de
a(
5
m
er
0
li V
Execution Time:
0.001s
TestCase2:
Input:
< hidden >
Expected Output:
< hidden >
Output:
1
0
)
.in
Description: Create a graph with dynamic memory allocation for both vertices and
ac
edges. Implement functions to:
ty.
rsi
Add a vertex.Add an edge between two vertices.Print the adjacency list of the
ive
graph.Input Format:
un
ias
The first line contains an integer n, the number of operations.Each of the next n lines
t
contains one of the following operations:ADD_VERTEX vertexADD_EDGE vertex1
lgo
vertex2PRINT_ADJ_LISTOutput Format:
ga
9@
For PRINT_ADJ_LIST, output the adjacency list for each vertex in the format: vertex:
14
Concepts Included:
m
er
Language Used: C
De
Source Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
)
.in
void addVertex(Graph* graph, int vertex) {
ac
if (vertex >= graph->numVertices) {
ty.
graph->adjLists = realloc(graph->adjLists, (vertex + 1) * sizeof(Node*));
rsi
for (int i = graph->numVertices; i <= vertex; i++) {
ive
graph->adjLists[i] = NULL;
un
}
ias
graph->numVertices = vertex + 1;
t
lgo
}
}
ga
9@
newNode->vertex = dest;
1
e1
newNode->next = graph->adjLists[src];
cs
graph->adjLists[src] = newNode;
4s
}
li.2
a
if (temp) {
m
er
while (temp) {
pa
printf("%d", temp->vertex);
e
temp = temp->next;
De
)
.in
while (temp) {
ac
Node* toFree = temp;
ty.
temp = temp->next;
rsi
free(toFree);
ive
}
un
}
ias
free(graph->adjLists);
t
lgo
free(graph);
}
ga
9@
int main() {
14
int numOperations;
80
scanf("%d", &numOperations);
1
e1
processOperations(numOperations);
cs
return 0;
4s
}
li.2
a
ep
Compilation Details:
de
a(
TestCase1:
m
er
li V
Input:
pa
e
Expected Output:
< hidden >
Output:
0: [1]
0: [1]
Expected Output:
< hidden >
Output:
2: [3]
3: [2]
2: [3]
3: [2]
)
.in
ac
Compilation Status: Passed
ty.
rsi
Execution Time:
ive
0.001s
un
iast
lgo
53. Structure-Based Sparse Matrix RepresentationProblem
ga
of the elements are zero. Your task is to store only the non-zero
1
matrices.
li.2
a
col, and value, representing the row index, column index, and the value of the non-zero
de
reading user inputs and storing only non-zero elements.Add two sparse matrices and
m
er
return the result as a new sparse matrix.Subtract one sparse matrix from another and
li V
return the result as a new sparse matrix.Input Format:First line: An integer n, the
pa
representing row, col, and value for each non-zero element of the first matrix.Followed
De
by the same format for the second matrix.Output Format:Print the resultant sparse
matrix after performing addition and subtraction operations.
Concepts Included:
gu 28 1st semester c programming
Language Used: C
Source Code:
#include <stdio.h>
)
.in
int value;
ac
} SparseMatrixElement;
ty.
rsi
// Function to read a sparse matrix from input
ive
void readMatrix(SparseMatrixElement matrix[], int *n) {
un
scanf("%d", n); // Read number of non-zero elements
ias
for (int i = 0; i < *n; i++) {
t
lgo
scanf("%d %d %d", &matrix[i].row, &matrix[i].col, &matrix[i].value);
}
ga
}
9@
14
int i = 0, j = 0, k = 0;
4s
li.2
result[k].row = matrix1[i].row;
pa
result[k].col = matrix1[i].col;
e
result[k].value = sum;
De
k++;
}
i++;
j++;
} else if (matrix1[i].row < matrix2[j].row || (matrix1[i].row == matrix2[j].row &&
matrix1[i].col < matrix2[j].col)) {
result[k++] = matrix1[i++];
} else {
result[k++] = matrix2[j++];
}
}
)
.in
// Iterate through both matrices
ac
while (i < n1 && j < n2) {
ty.
if (matrix1[i].row == matrix2[j].row && matrix1[i].col == matrix2[j].col) {
rsi
// Subtract values when both matrices have the same element
ive
int diff = matrix1[i].value - matrix2[j].value;
un
if (diff != 0) { // Only store non-zero results
ias
result[k].row = matrix1[i].row;
t
lgo
result[k].col = matrix1[i].col;
result[k].value = diff;
ga
k++;
9@
}
14
i++;
80
j++;
1
e1
result[k++] = matrix1[i++];
a
} else {
ep
subtract
a(
result[k].row = matrix2[j].row;
m
er
result[k].col = matrix2[j].col;
li V
as 0)
e
k++;
De
j++;
}
}
)
.in
ac
// Add the matrices
ty.
nResult = addMatrices(matrix1, n1, matrix2, n2, result);
rsi
ive
// Print the addition result
un
printf("Addition Result:\n");
ias
printMatrix(result, nResult);
t
lgo
printf("\n\nSubtraction Result:\n");
1
e1
printMatrix(result, nResult);
cs
return 0;
4s
}
li.2
a
ep
Compilation Details:
de
a(
TestCase1:
m
er
li V
Input:
pa
e
Expected Output:
< hidden >
Output:
Addition Result:
018
107
128
206
224
Subtraction Result:
012
1 0 -7
128
206
TestCase2:
Input:
)
< hidden >
.in
ac
Expected Output:
ty.
rsi
< hidden >
ive
un
Output:
Addition Result: iast
lgo
0 2 15
ga
2 1 20
9@
14
Subtraction Result:
80
025
1
e1
2 1 10
cs
Execution Time:
a
ep
de
0.001s
a(
m
er
Sample Input:3 41 2
Sample Output:Addition: 4.00 + 6.00iSubtraction: 2.00 + 2.00iMultiplication: -5.00 +
10.00iDivision: 2.20 - 0.40i
Concepts Included:
gu 28 1st semester c programming
Language Used: C
Source Code:
)
.in
#include <stdio.h>
ac
struct ComplexNumber {
ty.
rsi
float real;
ive
float imaginary;
un
};
ias
struct ComplexNumber add(struct ComplexNumber c1,
struct ComplexNumber c2) { t
lgo
struct ComplexNumber result;
ga
return result;
80
}
1
return result;
de
}
a(
c2.real;
return result;
}
struct ComplexNumber divide(struct ComplexNumber c1,
struct ComplexNumber c2) {
struct ComplexNumber result;
float denominator = c2.real * c2.real + c2.imaginary *
c2.imaginary;
if (denominator == 0) {
printf("Division by zero is not possible.\n");
result.real = 0;
result.imaginary = 0;
return result;
}
result.real = (c1.real * c2.real + c1.imaginary *
c2.imaginary) / denominator;
result.imaginary = (c1.imaginary * c2.real - c1.real *
c2.imaginary) / denominator;
return result;
}
void printComplex(struct ComplexNumber c) {
if (c.imaginary >= 0) {
printf("%.2f + %.2fi\n", c.real, c.imaginary);
} else {
printf("%.2f - %.2fi\n", c.real, -c.imaginary);
}
}
int main() {
struct ComplexNumber c1, c2, result;
)
.in
scanf("%f %f", &c1.real, &c1.imaginary);
ac
scanf("%f %f", &c2.real, &c2.imaginary);
ty.
result = add(c1, c2);
rsi
printf("Addition: ");
ive
printComplex(result);
un
result = subtract(c1, c2);
ias
printf("Subtraction: ");
t
lgo
printComplex(result);
result = multiply(c1, c2);
ga
printf("Multiplication: ");
9@
printComplex(result);
14
printf("Division: ");
1
e1
printComplex(result);
cs
return 0;
4s
}
li.2
a
ep
Compilation Details:
de
a(
TestCase1:
m
er
li V
Input:
pa
e
Expected Output:
< hidden >
Output:
Addition: 4.00 + 6.00i
Subtraction: 2.00 + 2.00i
Multiplication: -5.00 + 10.00i
Division: 2.20 - 0.40i
TestCase2:
Input:
< hidden >
Expected Output:
< hidden >
Output:
Addition: 7.00 + 9.00i
Subtraction: 3.00 + 3.00i
)
.in
Multiplication: -8.00 + 27.00i
ac
Division: 2.15 - 0.23i
ty.
rsi
Compilation Status: Passed
ive
un
Execution Time:
0.001s iast
lgo
ga
9@
and assessments. The program should allow the user to input data
li.2
and then calculate and display the average score for each course
a
ep
manage student data. Each student can be enrolled in multiple courses, and each
er
course can have several assessments. The number of courses and assessments are
li V
determined at runtime by user input. After the data is input, calculate the average
pa
score for each course and the overall average score for each student. Use dynamic
e
De
Language Used: C
Source Code:
#include <stdio.h>
#include <stdlib.h>
typedef struct {
int score;
} Assessment;
typedef struct {
)
.in
int numAssessments;
ac
Assessment *assessments;
ty.
} Course;
rsi
typedef struct {
ive
int numCourses;
un
Course *courses;
ias
} Student;
float calculateCourseAverage(Course course) { t
lgo
int totalScore = 0;
ga
totalScore += course.assessments[i].score;
14
}
80
}
cs
float totalCourseAverage = 0;
li.2
totalCourseAverage +=
ep
calculateCourseAverage(student.courses[i]);
de
}
a(
}
er
li V
int main() {
pa
int n;
e
scanf("%d", &n);
De
)
.in
printf("Overall Average: %.2f\n", overallAverage);
ac
}
ty.
for (int i = 0; i < n; i++) {
rsi
for (int j = 0; j < students[i].numCourses; j++) {
ive
free(students[i].courses[j].assessments);
un
}
ias
free(students[i].courses);
t
lgo
}
free(students);
ga
return 0;
9@
}
14
80
1
Compilation Details:
e1
cs
4s
TestCase1:
li.2
a
Input:
ep
de
Expected Output:
er
li V
Output:
De
Student 1:
Course 1 Average: 85.00
Course 2 Average: 77.50
Overall Average: 81.25
Student 2:
Course 1 Average: 90.00
Overall Average: 90.00
Expected Output:
< hidden >
Output:
Student 1:
Course 1 Average: 92.50
Overall Average: 92.50
)
Compilation Status: Passed
.in
ac
Execution Time:
ty.
rsi
ive
0.001s
un
ias
56. Handling Complex Data in Structures with PointersProblem t
lgo
management system for a store. Each product in the store can have
multiple suppliers, and each supplier can offer different prices for
14
80
the product. The program must calculate the average price of each
1
e1
Description:You need to create a program that manages a list of products, each with
a
multiple suppliers. For each product, the user will input the number of suppliers and
ep
the price offered by each supplier. The program should calculate and display the
de
average price for each product and identify the cheapest supplier. Use structures to
a(
represent the products and suppliers, and handle the input dynamically.
m
er
li V
representing the name of the supplier.A float price representing the price offered by
the supplier.Output Format:For each product, output the average price across all
suppliers.Output the name of the cheapest supplier for each product.
Concepts Included:
gu 28 1st semester c programming
Language Used: C
Source Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct {
char supplierName[50];
float price;
} Supplier;
)
.in
ac
typedef struct {
ty.
char productName[50];
rsi
int numSuppliers;
ive
Supplier *suppliers;
un
} Product;
ias
t
lgo
void inputProductData(Product *products, int numProducts) {
for (int i = 0; i < numProducts; ++i) {
ga
scanf("%s", products[i].productName);
9@
scanf("%d", &products[i].numSuppliers);
14
sizeof(Supplier));
1
e1
cs
}
a
}
ep
}
de
a(
int main() {
int numProducts;
scanf("%d", &numProducts);
)
.in
ac
inputProductData(products, numProducts);
ty.
calculateAndPrintAverages(products, numProducts);
rsi
freeProductData(products, numProducts);
ive
un
free(products);
ias
return 0;
t
lgo
}
ga
9@
Compilation Details:
14
80
TestCase1:
1
e1
cs
Input:
4s
li.2
Expected Output:
de
a(
Output:
li V
pa
Product: Laptop
e
TestCase2:
Input:
< hidden >
Expected Output:
< hidden >
Output:
Product: Printer
Average Price: 147.75
Cheapest Supplier: Supplier2
)
0.001s
.in
ac
ty.
rsi
57. Complex Macro with Multiple ParametersProblem Statement:
ive
un
Write a C program that uses a complex macro with multiple parameters to perform a
ias
series of operations on two integers. The macro should compute the result of a
t
mathematical expression and print both intermediate and final results. Use the macro
lgo
to compute the following expression: (a * b + c) / d, where a, b, c, and d are provided
ga
by the user.
9@
14
Description:
80
user for values of a, b, c, and d.Use the macro to perform the calculation and print the
cs
d.
a(
m
result of (a * b + c) / d: 5
e
De
Concepts Included:
gu 28 1st semester c programming
Language Used: C
Source Code:
#include <stdio.h>
#define CALC(a, b, c, d) (((a) * (b) + (c)) / (d))
int main() {
int a, b, c, d;
scanf("%d %d %d %d", &a, &b, &c, &d);
int intermediate1 = a * b;
int intermediate2 = intermediate1 + c;
int finalResult = CALC(a, b, c, d);
printf("Intermediate result of a * b: %d\n", intermediate1);
printf("Intermediate result of a * b + c: %d\n",
intermediate2);
printf("Final result of (a * b + c) / d: %d\n", finalResult);
return 0;
}
)
Compilation Details:
.in
ac
ty.
TestCase1:
rsi
ive
Input:
un
ias
< hidden >
t
lgo
Expected Output:
ga
9@
Output:
80
1
e1
Intermediate result of a * b: 6
cs
Intermediate result of a * b + c: 10
4s
Final result of (a * b + c) / d: 5
li.2
Execution Time:
a(
m
0.001s
er
li V
pa
TestCase2:
e
De
Input:
< hidden >
Expected Output:
< hidden >
Output:
Intermediate result of a * b: 30
Intermediate result of a * b + c: 37
Final result of (a * b + c) / d: 12
)
.in
savings structure with:
ac
ty.
balance (float) for the current balance.interestRate (float) for the annual interest
rsi
rate.checking structure with:
ive
balance (float) for the current balance.overdraftLimit (float) for the overdraft
un
limit.Define a structure BankAccount that includes:
ias
t
lgo
A string accountHolderName for the name of the account holder.An integer
ga
For Savings Account: Display the balance and interest rate.For Checking Account:
80
Display the balance and overdraft limit.Input Format:The first line contains the name
1
e1
of the account holder.The second line contains an integer representing the account
cs
type (1 for Savings Account, 2 for Checking Account).If the account type is 1, the next
4s
line contains two floats: balance and interest rate.If the account type is 2, the next
li.2
line contains two floats: balance and overdraft limit.Output Format:Display the
a
Concepts Included:
gu 28 1st semester c programming
Language Used: C
Source Code:
#include <stdio.h>
struct {
float balance;
float overdraftLimit;
} checking;
};
)
.in
union AccountDetails accountDetails;
ac
};
ty.
rsi
int main() {
ive
// Declare a bank account structure
un
struct BankAccount account;
iast
lgo
// Input the account holder's name
fgets(account.accountHolderName, sizeof(account.accountHolderName), stdin);
ga
9@
if (account.accountHolderName[len - 1] == '\n') {
1
e1
account.accountHolderName[len - 1] = '\0';
cs
}
4s
li.2
scanf("%d", &account.accountType);
ep
de
if (account.accountType == 1) {
m
er
&account.accountDetails.savings.interestRate);
e
Compilation Details:
TestCase1:
Input:
< hidden >
Expected Output:
< hidden >
)
.in
ac
Output:
ty.
rsi
Savings Account Balance: 1500.75
ive
Annual Interest Rate: 2.50%
un
ias
Compilation Status: Passed
t
lgo
Execution Time:
ga
9@
0.001s
14
80
TestCase2:
1
e1
cs
Input:
4s
li.2
Expected Output:
de
a(
Output:
li V
pa
Sample Input:10
)
Sample Output:Debug: Input value is 10The number is even
.in
ac
ty.
rsi
Completion Status: Completed
ive
un
Concepts Included:
iast
lgo
gu 28 1st semester c programming
ga
9@
Language Used: C
14
80
Source Code:
1
e1
cs
#include <stdio.h>
4s
#define DEBUG
li.2
int main() {
a
int number;
ep
scanf("%d", &number);
de
#ifdef DEBUG
a(
#endif
li V
if (number % 2 == 0) {
pa
} else {
De
Compilation Details:
TestCase1:
Input:
< hidden >
Expected Output:
< hidden >
Output:
Debug: Input value is 10
The number is even
TestCase2:
)
.in
ac
Input:
ty.
rsi
< hidden >
ive
un
Expected Output:
< hidden > iast
lgo
ga
Output:
9@
Execution Time:
li.2
a
0.001s
ep
de
a(
Traverse the 2D array and compute the sum of all elements.Compute the product of
all elements.Count the number of elements greater than a given
threshold.Description:You need to implement a recursive function that takes a pointer
to the 2D array and its dimensions (number of rows and columns).The function
should return a structure containing the sum, product, and count of elements greater
than a threshold.Input Format:The first line contains two integers: rows and cols
(dimensions of the 2D array).The next rows lines each contain cols integers
representing the 2D array elements.The last line contains an integer threshold.Output
Format:Print the sum, product, and count of elements greater than the threshold.
Sample Input:2 31 2 34 5 64
Concepts Included:
gu 28 1st semester c programming
Language Used: C
Source Code:
#include <stdio.h>
#define MAX_ROWS 100
#define MAX_COLS 100
typedef struct {
)
.in
int sum;
ac
long long product;
ty.
int countGreaterThanThreshold;
rsi
} ArrayResult;
ive
ArrayResult processArray(int arr[MAX_ROWS][MAX_COLS],
un
int row, int col, int rows, int cols, int threshold) {
ArrayResult result = {0, 1, 0};
iast
lgo
if (row >= rows) {
ga
return result;
9@
}
14
}
e1
result.sum += currentElement;
4s
result.product *= currentElement;
li.2
result.countGreaterThanThreshold++;
de
}
a(
result.sum += nextResult.sum;
li V
result.product *= nextResult.product;
pa
result.countGreaterThanThreshold +=
e
De
nextResult.countGreaterThanThreshold;
return result;
}
int main() {
int rows, cols, threshold;
int arr[MAX_ROWS][MAX_COLS];
scanf("%d %d", &rows, &cols);
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
scanf("%d", &arr[i][j]);
}
}
scanf("%d", &threshold);
ArrayResult result = processArray(arr, 0, 0, rows, cols,
threshold);
printf("Sum: %d\n", result.sum);
printf("Product: %lld\n", result.product);
printf("Count greater than %d: %d\n", threshold,
result.countGreaterThanThreshold);
return 0;
}
Compilation Details:
TestCase1:
Input:
)
.in
< hidden >
ac
Expected Output:
ty.
rsi
< hidden >
ive
un
Output:
iast
lgo
Sum: 21
Product: 720
ga
Execution Time:
e1
cs
0.001s
4s
li.2
a
TestCase2:
ep
de
Input:
a(
m
Expected Output:
pa
e
De
Output:
Sum: 31
Product: 2160
Count greater than 1: 5