Lab Files
Lab Files
Page No: 1
S.No: 1 Exp. Name: Speed Calculator
26
Aim:
ID: 247Y1A6790
Write a C program that should prompt the user to input the distance traveled and the
time taken and calculate the speed using the formula: Speed = Distance / Time.
Input Format:
• A single line which accepts the distance and time as space separated integers.
Output Format:
• Prints the speed as an integer output after calculating using the given formula
Source Code:
speedCalculator.c
2024-2028-CSD-B
#include<stdio.h>
void main()
{
int d,t,s;
scanf("%d%d",&d,&t);
s=d/t;
printf("%d",s);
User Output
400 40
10
Test Case - 2
User Output
100 20
5
Date: 2024-09-
S.No: 2 Exp. Name: Area of a Circle
Page No: 2
26
Aim:
Write a C program that prompts the user to enter the radius of the circle and computes
ID: 247Y1A6790
the area of a circle.
Note:
• Take the Pi value as 3.14.
• Print the result up to 3 decimal places.
Input format:
The input is the floating point value that represents the radius of a circle.
Output format:
The output is the floating point value that represents the area of the circle.
2024-2028-CSD-B
Source Code:
circleArea.c
#include<stdio.h>
void main()
{
User Output
1.23
4.751
Test Case - 2
User Output
2.5
19.625
Marri Laxman Reddy Institute of Technology and Management (Autonomous) 2024-2028-CSD-B ID: 247Y1A6790 Page No: 3
Date: 2024-10-
S.No: 3 Exp. Name: Fuel Efficiency Calculation
Page No: 4
03
Aim:
Write a C program that calculates the fuel efficiency of a vehicle. The program should
ID: 247Y1A6790
prompt the user to input the distance traveled and the amount of fuel consumed. The
fuel efficiency should be calculated in miles per gallon (MPG) using the formula: MPG =
Distance / Fuel Consumption.
Input Format
A single line of input containing two space-separated floating-point numbers:
• The first number represents the distance traveled (in miles).
• The second number represents the amount of fuel consumed (in gallons).
Output Format
Displays the fuel efficiency in miles per gallon (MPG) rounded to two decimal places.
2024-2028-CSD-B
Source Code:
mpgCalculator.c
#include<stdio.h>
void main()
{
User Output
200 20
10.00
Test Case - 2
User Output
200.4 15.6
12.85
Marri Laxman Reddy Institute of Technology and Management (Autonomous) 2024-2028-CSD-B ID: 247Y1A6790 Page No: 5
Exp. Name: Calculation of the discount Date: 2024-10-
S.No: 4
Page No: 6
price 03
Aim:
Write a C program that calculates the discounted price of an item. The program should
ID: 247Y1A6790
prompt the user to input the original price and the discount percentage. The discounted
price should be calculated using the formula: Discounted Price = Original Price -
(Original Price * Discount Percentage /100).
Input Format
A single line of input containing two space-separated floating-point numbers.
• The first number represents the original price of the item.
• The second number represents the discount percentage.
Output Format
Displays the discounted price of the item rounded to two decimal places
2024-2028-CSD-B
Source Code:
discountPriceCalc.c
#include<stdio.h>
void main()
{
User Output
600 10
540.00
Test Case - 2
User Output
735.00
1050 30
Marri Laxman Reddy Institute of Technology and Management (Autonomous) 2024-2028-CSD-B ID: 247Y1A6790 Page No: 7
Date: 2024-10-
S.No: 5 Exp. Name: Monthly Budget Tracker
Page No: 8
03
Aim:
Write a C program prompt the user to input their income and expenses and calculate the
ID: 247Y1A6790
total savings using the formula: Total Savings = Income - Total Expenses.
Input Format
A single line of input containing two space-separated floating-point numbers:
• The first number represents the income.
• The second number represents the expenses.
Output Format
Displays the savings of the month rounded to three decimal places
Source Code:
2024-2028-CSD-B
budgetCalculator.c
#include<stdio.h>
void main()
{
float income,expenses;
scanf("%f%f",&income,&expenses);
User Output
30000 20000
10000.000
Test Case - 2
User Output
55000 30000
25000.000
Exp. Name: Loan amortization Date: 2024-10-
S.No: 6
Page No: 9
calculator 03
Aim:
Write a C program that calculates the monthly payment for a loan. The program should
ID: 247Y1A6790
prompt the user to input the loan amount, interest rate, and loan duration. The monthly
payment should be calculated using the formula: Monthly Payment = (Loan Amount *
Interest Rate * (1+ Interest Rate) ) / ((1 + Interest Rate)
Duration Duration−1
).
Input Format
• First Line : A floating-point number that represents the total amount of the loan.
• Second Line : A floating-point number that represents the monthly interest rate (as
a decimal). For example, 5% interest rate should be entered as 0.05.
• Third Line : An integer representing the number of months over which the loan will
be repaid.
2024-2028-CSD-B
Output Format
• Displays the calculated monthly payment rounded to two decimal places.
loanCalculator.c
0.01
0.005
10000
50000
888.49
966.64
User Output
User Output
Test Case - 2
Marri Laxman Reddy Institute of Technology and Management (Autonomous) 2024-2028-CSD-B ID: 247Y1A6790 Page No: 10
Date: 2024-10-
S.No: 7 Exp. Name: Surface Area of Room
Page No: 11
03
Aim:
You need to calculate the surface area of a rectangular room. The surface area can be
ID: 247Y1A6790
calculated using the formula: Surface Area = 2 * (Length * Width + Length * Height
+Width * Height).
Write a C program that prompts the user to input the length, width, and height of the
room and calculates the surface area using the above formula.
Input Format:
The program should prompt the user to enter the following:
• Length of the room (a floating-point number)
• Width of the room (a floating-point number)
• Height of the room (a floating-point number)
2024-2028-CSD-B
Output Format:
The program should output the surface area of the room, rounded to two decimal places.
Source Code:
surfaceArea.c
#include<stdio.h>
User Output
30
40
60
10800.00
32
70
55
15700.00
User Output
Test Case - 2
Marri Laxman Reddy Institute of Technology and Management (Autonomous) 2024-2028-CSD-B ID: 247Y1A6790 Page No: 12
Exp. Name: Convert given time to Date: 2024-10-
S.No: 8
Page No: 13
minutes 03
Aim:
You need to convert a given time specified in hours and minutes to minutes only. Write a
ID: 247Y1A6790
C program that prompts the user to input the time in hours and minutes and then
displays the total time converted to minutes.
Input Format:
• The program should prompt the user to enter the hours and minutes as space-
separated integers
Output Format:
• The program should output the total time converted to minutes.
2024-2028-CSD-B
Source Code:
convertToMinutes.c
#include<stdio.h>
void main()
{
User Output
1 20
80
Test Case - 2
User Output
150
2 30
Marri Laxman Reddy Institute of Technology and Management (Autonomous) 2024-2028-CSD-B ID: 247Y1A6790 Page No: 14
Date: 2024-10-
S.No: 9 Exp. Name: Coin Distribution
Page No: 15
03
Aim:
You have a money pouch containing a certain total amount of money. The pouch
ID: 247Y1A6790
contains an equal number of 25 paise coins, 50 paise coins, and 1 rupee coins. Write a C
program to determine how many of each type of coin are present if the total amount of
money in the pouch is given.
Input Format:
• The program should prompt the user to enter the total amount of money in the
pouch (in rupees).
Output Format:
The program should output the following in separate lines:
• The number of 25 paise coins.
2024-2028-CSD-B
• The number of 50 paise coins.
• The number of 1 rupee coins.
Note:
• 1 rupee = 2 * 50 paise coins
• 1 rupee = 4 * 25 paise coins
Source Code:
1400
User Output
User Output
Test Case - 2
Marri Laxman Reddy Institute of Technology and Management (Autonomous) 2024-2028-CSD-B ID: 247Y1A6790 Page No: 16
Date: 2024-10-
S.No: 10 Exp. Name: Velocity Calculation
Page No: 17
13
Aim:
Write a C program to calculate the final velocity of an object based on its initial velocity,
ID: 247Y1A6790
acceleration, and time. Use the following formula to calculate the final velocity: Velocity
= Initial Velocity + (Acceleration * Time).
Input Format:
The program should prompt the user to input :
• Initial Velocity (in meters per second)
• Acceleration (in meters per second squared)
• Time (in seconds) on separate lines
Output Format:
The program should display the final velocity (in meters per second) calculated using the
2024-2028-CSD-B
formula.
Source Code:
velocityCalculator.c
#include<stdio.h>
User Output
10
2
5
20.00 m/s
0
10
9.8
98.00 m/s
User Output
Test Case - 2
Marri Laxman Reddy Institute of Technology and Management (Autonomous) 2024-2028-CSD-B ID: 247Y1A6790 Page No: 18
Exp. Name: Area of Triangle using Date: 2024-10-
S.No: 11
Page No: 19
Heron's Formula 08
Aim:
Write a C program to calculate the area of a triangle given the lengths of its three sides.
ID: 247Y1A6790
Use Heron's formula to compute the area: Area = √(s * (s - Side1) * (s - Side2) * (s -
Side3)), where s = (Side1 + Side2 + Side3) / 2.
Input Format:
The program should prompt the user to input:
• Length of Side1 (in floating-point numbers)
• Length of Side2 (in floating-point numbers)
• Length of Side3 (in floating-point numbers)
Output Format:
The program should display the area of the triangle (rounded off to two decimal places)
2024-2028-CSD-B
calculated using Heron's formula.
Source Code:
areaOfTriangle.c
#include<stdio.h>
#include<math.h>
User Output
5
12
13
30.00
8
6
10
24.00
User Output
Test Case - 2
Marri Laxman Reddy Institute of Technology and Management (Autonomous) 2024-2028-CSD-B ID: 247Y1A6790 Page No: 20
Exp. Name: Salary Calculation of Date: 2024-10-
S.No: 12
Page No: 21
Employee 08
Aim:
ABC Company needs to calculate the monthly salary for its employees based on several
ID: 247Y1A6790
components. The salary calculation follows these rules:
1. Basic Pay: A fixed amount given to each employee.
2. DA (Dearness Allowance): 20% of the Basic Pay.
3. HRA (House Rent Allowance): 10% of the Basic Pay.
4. Gross Salary: Sum of Basic Pay, DA, and HRA.
5. Net Salary: Gross Salary minus deductions for taxes and provident fund.
Write a C program to compute the Gross Salary and Net Salary of an employee based on
the following input values:
• Basic Pay
• Deductions for Taxes
• Deductions for Provident Fund
2024-2028-CSD-B
The program should output the Gross Salary and Net Salary.
Input Format
A single line containing three space-separated floating-point numbers:
• Basic Pay
• Deductions for Taxes
• Deductions for Provident Fund
salaryCalculation.c
#include<stdio.h>
void main()
{
float basic,dt,dp;
scanf("%f%f%f",&basic,&dt,&dp);
float da=0.20*basic;
float hra=0.10*basic;
float gross=basic+da+hra;
printf("%.2f\n",gross);
float net=gross-(dt+dp);
printf("%.2f\n",net);
}
Execution Results - All test cases have succeeded!
Page No: 22
Test Case - 1
User Output
30000 1000 500
ID: 247Y1A6790
39000.00
37500.00
Test Case - 2
User Output
45000 2500 1000
58500.00
55000.00
2024-2028-CSD-B
Marri Laxman Reddy Institute of Technology and Management (Autonomous)
Date: 2024-10-
S.No: 13 Exp. Name: Average of Three Values
Page No: 23
13
Aim:
Raju's father caught him tinkering with the computer and reminded him to focus on his
ID: 247Y1A6790
homework first. The math question assigned to him involves calculating the average of
three integers. Since he's unsure how to proceed, he seeks your assistance. Write a C
program to compute the average of three integers. The program should prompt the user
to enter these integers, calculate their average, and display the result formatted to two
decimal places.
Input/Output Format:
2024-2028-CSD-B
Requirements:
• Use integer variables to store the input values.
• Perform type conversion as necessary to compute the average as a floating-point
number.
• Print the result formatted to two decimal places using printf.
Source Code:
#include<stdio.h>
void main()
{
int a,b,c;
float avg;
scanf("%d%d%d",&a,&b,&c);
avg=(float)(a+b+c)/3;
printf("%.2f\n",avg);
}
User Output
10 20 30
20.00
0.00
5.00
555
25.00
-10 0 10
15 25 35
User Output
User Output
User Output
Test Case - 4
Test Case - 3
Test Case - 2
Marri Laxman Reddy Institute of Technology and Management (Autonomous) 2024-2028-CSD-B ID: 247Y1A6790 Page No: 24
Date: 2024-10-
S.No: 14 Exp. Name: Temperature Conversion
Page No: 25
13
Aim:
You are tasked with creating a program to convert temperatures between Celsius and
ID: 247Y1A6790
Fahrenheit. Your program should handle user input for temperature values and provide
accurate conversions, allowing seamless conversion between Celsius and Fahrenheit for
your weather forecasting needs.
Input Format:
The program first prompts for a temperature in for conversion.
Output Format:
Print the conversion of the temperature to Fahrenheit formatted to two decimals.
Print the conversion of the same temperature to Celsius formatted to two decimals.
Source Code:
2024-2028-CSD-B
temperature.c
#include<stdio.h>
int main() {
float t,c,f;
printf("Enter temperature: ");
User Output
Enter temperature:
35
35.00 Celsius is equal to 95.00 Fahrenheit
35.00 Fahrenheit is equal to 1.67 Celsius
Test Case - 2
Page No: 26
User Output
Enter temperature:
45.5
45.50 Celsius is equal to 113.90 Fahrenheit
ID: 247Y1A6790
45.50 Fahrenheit is equal to 7.50 Celsius
2024-2028-CSD-B
Marri Laxman Reddy Institute of Technology and Management (Autonomous)
Date: 2024-10-
S.No: 15 Exp. Name: The Tall Men Next Door
Page No: 27
13
Aim:
XYZ Company has four brothers living next door, each with a different height. The
ID: 247Y1A6790
company knows the following details:
6. The average height of the four brothers is provided by the user.
7. The difference in height between the first and second brothers, and the second
and third brothers is 2 inches each.
8. The difference in height between the third and the fourth brother is 6 inches.
Write a C program that takes the average height of the four brothers as input and
calculates their individual heights based on the given conditions. The program should
output: The height of each of the four brothers.
Input Format:
• A single floating-point number representing the average height of the four
2024-2028-CSD-B
brothers.
Output Format:
• Four lines of output displaying the height of each brother.
Source Code:
findHeights.c
74.0
User Output
User Output
Test Case - 2
Test Case - 1
Marri Laxman Reddy Institute of Technology and Management (Autonomous) 2024-2028-CSD-B ID: 247Y1A6790 Page No: 28
Date: 2024-10-
S.No: 16 Exp. Name: Driving through the country
Page No: 29
13
Aim:
You have decided to travel through the country, increasing your travel distance each day.
ID: 247Y1A6790
The journey follows these rules:
9. On the first day, you traveled a certain number of miles.
10. On the last day, you traveled a different number of miles.
11. Each day, you increased your travel distance by a fixed number of miles.
Write a C program that calculates the following:
12. The total number of days traveled.
13. The total distance traveled over the entire journey.
Input Format:
• An integer representing the distance traveled on the first day (in miles).
• An integer representing the distance traveled on the last day (in miles).
2024-2028-CSD-B
• An integer representing the daily increment in distance (in miles).
Output Format:
• The number of days traveled.
• The total distance traveled.
Source Code:
User Output
5
9
9
5
3
50
10
29
270
153
User Output
Test Case - 2
Marri Laxman Reddy Institute of Technology and Management (Autonomous) 2024-2028-CSD-B ID: 247Y1A6790 Page No: 30
Date: 2024-10-
S.No: 17 Exp. Name: Monitor water level
Page No: 31
13
Aim:
There is a beautiful pond in a park, filled with clear water. The park management wants to
ID: 247Y1A6790
monitor the water level in the pond regularly to ensure it remains at an optimal level.
They have asked you to create a C program to help them with this task. Develop a
program to monitor the water level in the pond and notify the park management if it falls
below a certain threshold.
Input Format
• Current Water Level: A floating-point number representing the current water level
in meters.
• Threshold Level: A floating-point number representing the threshold water level in
meters.
2024-2028-CSD-B
Output Format
• If the water level is below the threshold level print the message "The water level
has fallen below the threshold level"
• Otherwise, print "The water level is at an acceptable level"
Source Code:
Page No: 32
1.5 2
The water level has fallen below the threshold level
Test Case - 2
ID: 247Y1A6790
User Output
2.5 2
The water level is at an acceptable level
2024-2028-CSD-B
Marri Laxman Reddy Institute of Technology and Management (Autonomous)
Date: 2024-10-
S.No: 18 Exp. Name: Maximum submissions
Page No: 33
13
Aim:
You are participating in a programming contest where you can make one submission
ID: 247Y1A6790
every 45 seconds. The contest lasts for a given number of minutes. Develop a C program
to determine the maximum number of submissions you can make during the contest.
Input Format:
• An integer representing the duration of the contest in minutes.
Output Format:
• An integer representing the maximum number of submissions possible during the
contest.
Source Code:
2024-2028-CSD-B
maxSubmissions.c
#include<stdio.h>
void main()
{
int cd,sub,sec;
scanf("%d",&cd);
User Output
2
3
Test Case - 2
User Output
7
5
Marri Laxman Reddy Institute of Technology and Management (Autonomous) 2024-2028-CSD-B ID: 247Y1A6790 Page No: 34
Date: 2024-10-
S.No: 19 Exp. Name: Largest Number
Page No: 35
13
Aim:
Michael wants to find the largest number among a set of given numbers. Help Michael to
ID: 247Y1A6790
write a C program to determine the largest number from the given inputs.
Input Format:
• An integer representing the number of elements in the set.
• Followed by the integers representing the elements in the set.
Output Format:
• The largest number among the given inputs
Source Code:
2024-2028-CSD-B
largestNum.c
#include<stdio.h>
int main()
{
int nes;
scanf("%d",&nes);
66
44
66
45
21
44
29
User Output
User Output
Test Case - 2
Marri Laxman Reddy Institute of Technology and Management (Autonomous) 2024-2028-CSD-B ID: 247Y1A6790 Page No: 36
Date: 2024-10-
S.No: 20 Exp. Name: Cost of the painting
Page No: 37
13
Aim:
A construction worker needs to paint the exterior walls of a rectangular building. The
ID: 247Y1A6790
dimensions of the walls are L meters in length, H meters in height, and W meters in width.
If the cost of painting is Rs. 20 per square meter, what will be the total cost of painting
the walls? Write a C program to implement the given
Input Format
• A floating-point number representing the length of the building in meters.
• A floating-point number representing the height of the building in meters.
• A floating-point number representing the width of the building in meters.
Output Format
• A floating-point number representing the total cost of painting the exterior walls,
2024-2028-CSD-B
formatted to two decimal places.
Hint: Use the surface area of the exterior walls to calculate the total painting cost.
Source Code:
costOfPainting.c
User Output
10.0
5.0
6.0
5.0
5.0
20.0
5000.00
3200.00
User Output
Test Case - 2
Marri Laxman Reddy Institute of Technology and Management (Autonomous) 2024-2028-CSD-B ID: 247Y1A6790 Page No: 38
Exp. Name: Finding the number of liters Date: 2024-10-
S.No: 21
Page No: 39
of ice cream left 13
Aim:
An ice cream vendor brings i liter of ice cream to a fair. Each cone requires 0.25 liters of
ID: 247Y1A6790
ice cream. If the vendor sells 80 cones, Develop a C program to find the number of liters
of ice cream left with the vendor.
Input Format:
• A floating-point number representing the total amount of ice cream brought by
the vendor (in liters).
Output Format:
• A floating-point number representing the amount of ice cream left with the vendor
(in liters), rounded to two decimal places.
Source Code:
2024-2028-CSD-B
icecreamLeft.c
#include<stdio.h>
int main()
{
float
User Output
100
80.00
Test Case - 2
60
40.00
User Output
Marri Laxman Reddy Institute of Technology and Management (Autonomous) 2024-2028-CSD-B ID: 247Y1A6790 Page No: 40
Exp. Name: Calculating the total Date: 2024-10-
S.No: 22
Page No: 41
number of guests 13
Aim:
Amanda is planning a party and wants to determine the total number of guests
ID: 247Y1A6790
attending. Assist Amanda by writing a C program to calculate the total number of guests
based on the number of adults and children invited.
Input Format:
• An integer representing the number of adults invited to the party.
• An integer representing the number of children invited to the party.
Output Format:
• An integer representing the total number of guests attending the party.
Source Code:
2024-2028-CSD-B
guestsCalculation.c
#include<stdio.h>
int main()
{
int a,c,g;
scanf("%d%d",&a,&c);
User Output
5
13
18
Test Case - 2
User Output
4
24
20
Marri Laxman Reddy Institute of Technology and Management (Autonomous) 2024-2028-CSD-B ID: 247Y1A6790 Page No: 42
Exp. Name: Calculate and display the
Date: 2024-10-
Page No: 43
S.No: 23 maturity amount using the Simple
13
Interest.
Aim:
ID: 247Y1A6790
You are working as a financial analyst at a bank. As part of your job, you need to calculate
the maturity amount for fixed deposits (FD) based on the principal amount, interest rate,
and duration. Write a C program that takes the principal amount, interest rate, and
duration (in years) as input from the user.
Calculate and display the maturity amount using the simple interest formula: Maturity
Amount = Principal + (Principal * Interest Rate * Duration)/100.
Input Format:
• Input the principal amount, interest rate as float and duration separated by a space
2024-2028-CSD-B
Constraints:
• 1 <= amount <= 1000000
• 0 <= interest rate <= 10
• 1 <= duration <= 20
Output Format:
• Display the maturity amount upto two decimal points
MaturityAmount.c
#include<stdio.h>
int main()
{
float pa,ir,ma;
float d;
scanf("%f%f%f",&pa,&ir,&d);
ma=pa+(pa*ir*d)/100;
printf("%.2f",ma);
}
User Output
25000 1.2 2
25600.00
Page No: 44
Test Case - 2
User Output
ID: 247Y1A6790
5000 5 2
5500.00
Test Case - 3
User Output
1000 7.5 3
1225.00
2024-2028-CSD-B
Test Case - 4
User Output
2500 3.2 4.5
2860.00
User Output
8000 2 1.5
8240.00
Exp. Name: Calculate the area of a Date: 2024-10-
S.No: 24
Page No: 45
rectangle. 13
Aim:
Jenny, a budding mathematician, was studying the concept of area and perimeter. She
ID: 247Y1A6790
was given a rectangular garden with a known length and width. Jenny wondered if she
could find the area without knowing the width. Can you help Jenny derive a formula to
calculate the area of a rectangle using only the length and perimeter?
Input Format:
• Input the length and perimeter of rectangle of type double separated with a space
Constraints:
• 1 <= length <= 100000
• 1 <= perimeter <= 1000000
2024-2028-CSD-B
Output Format:
• Display Area of the Rectangle rounded upto two decimals
Source Code:
Area.c
User Output
5 18
Test Case - 2
Page No: 46
User Output
10 40
100.00
ID: 247Y1A6790
Test Case - 3
User Output
5 50
100.00
Test Case - 4
2024-2028-CSD-B
User Output
8 30
56.00
Test Case - 5
Page No: 47
theorem. 13
Aim:
Write a C program to calculate the hypotenuse of a right-angled triangle given the
ID: 247Y1A6790
lengths of its two perpendicular sides. The program should prompt the user to enter the
lengths and then display the result.
Formula:
Hypotenuse² = Side1² + Side2²
Input Format:
Enter two floating-point numbers for side1 and side2.
Constraints:
1 ≤ side1, side2 ≤ 100000
2024-2028-CSD-B
Output Format:
Display the hypotenuse as a float rounded to two decimal places.
Source Code:
Triangle.c
User Output
34
5.00
11
5 12
1.41
13.00
12.10
7.5 9.5
User Output
User Output
User Output
Test Case - 4
Test Case - 3
Test Case - 2
Marri Laxman Reddy Institute of Technology and Management (Autonomous) 2024-2028-CSD-B ID: 247Y1A6790 Page No: 48
Exp. Name: Sum of first n natural Date: 2024-10-
S.No: 26
Page No: 49
numbers 13
Aim:
Once upon a time, there was a mathematician named Alex. Alex loved solving
ID: 247Y1A6790
mathematical problems and puzzles. One day, Alex came across an ancient scroll that
contained a secret formula to calculate the sum of the first n natural numbers. The scroll
mentioned that by using the formula, one could find the sum of any given number of
natural numbers without having to manually add them up. Alex was intrigued and
decided to test the formula. Can you help Alex implement a C program that uses the
formula to calculate the sum of the first n natural numbers?
Input Format:
• Input an integer n.
2024-2028-CSD-B
Constraints:
• 1 <= n <= 105
Output Format:
• Display the sum of the first n natural numbers.
Source Code:
#include<stdio.h>
int main()
{
int n,sum;
scanf("%d",&n);
sum=(n*(n+1))/2;
printf("%d\n",sum);
}
User Output
5
15
Test Case - 2
Page No: 50
User Output
1
1
ID: 247Y1A6790
Test Case - 3
User Output
20
210
Test Case - 4
2024-2028-CSD-B
User Output
10
55
Test Case - 5
Page No: 51
points 13
Aim:
Once upon a time in a small town, there were two friends, Kavi and Jei, who were
ID: 247Y1A6790
fascinated by the concept of slopes in mathematics. They loved exploring the hills and
valleys around their town and wondered how they could calculate the slope of any given
landscape. One sunny day, while hiking up a hill, Kavi and Jei discovered an ancient map
that had the secret to finding the slope of a line between two points. The map indicated
that by using the coordinates of two points, they could determine the slope of the line
connecting them. Excited about their discovery, Kavi and Jei decided to create a C
program that could calculate the slope for any two points. They wanted to share their
program with others so that everyone could explore the slopes of various landscapes.
Help Kavi and Jei to implement the program.
2024-2028-CSD-B
Input Format
• Input the coordinates of two points: x1, y1, x2, y2 of type float separated by space.
Constraints:
• 1 <= x1, y1, x2, y2 <= 106
Slope.c
#include<stdio.h>
int main()
{
float x1,y1,x2,y2,slope;
scanf("%f%f%f%f",&x1,&y1,&x2,&y2);
slope=(y2-y1)/(x2-x1);
printf("%.2f\n",slope);
}
Page No: 52
6 3 18 36
2.75
Test Case - 2
ID: 247Y1A6790
User Output
2.56 2.65 5.5 6.7
1.38
Test Case - 3
User Output
14.5 13.7 16.4 17.8
2024-2028-CSD-B
2.16
Test Case - 4
User Output
23.45 25.6 22.4 23.45
Page No: 53
two points. 13
Aim:
Ravi and Kavi are on an exciting treasure hunt adventure, following a map with hidden
ID: 247Y1A6790
treasures located at different coordinates. They want to calculate the distance between
two treasures to determine how far apart they are.
Help them to write a C program that prompts the user to enter the coordinates of two
treasures: Treasure A and Treasure B and calculate the distance between them. The
coordinates should be in the form (x, y).
Input Format:
• Input x1 and y1 in first line
2024-2028-CSD-B
• Input x2 and y2 in second line
Constraints:
•1≤x 1 , y1 , x2 , y2 ≤ 10
5
Output Format:
• Display the distance between two points.
distance.c
#include<stdio.h>
#include<math.h>
int main()
{
float x1,y1;
float x2,y2;
float d;
scanf("%f%f%f%f",&x1,&y1,&x2,&y2);
d=sqrt(pow(x2-x1,2)+pow(y2-y1,2));
printf("%.2f\n",d);
}
Page No: 54
22
44
2.83
ID: 247Y1A6790
Test Case - 2
User Output
3.5 1.0
1.0 3.5
3.54
Test Case - 3
2024-2028-CSD-B
User Output
-3.0 -4.0
3.0 4
10.00
User Output
10.0 10
00
14.14
Test Case - 5
User Output
-6 -4
-2 -4
4.00
Date: 2024-10-
S.No: 29 Exp. Name: Coconut Shot Calculator
Page No: 55
13
Aim:
Imagine a scenario where there is a coconut tree with multiple coconuts hanging from it.
ID: 247Y1A6790
There is a person standing at a distance of D meters away from the tree. The coconuts are
positioned at a height of H meters from the ground. Could you please help him to write a
C program that calculates the angle at which the person should aim in order to hit the
coconuts?
Hint: You can use the inverse tangent function (atan() in C) to determine the angle based
on the ratio of the height of the coconuts to the distance from the tree.
Input Format:
First line contains an integer D representing the distance from the person to the tree
Second line contains an integer H representing the height of the tree
2024-2028-CSD-B
Constraints:
1 <= D, H <= 105
Output Format:
Return the angle in float format
angleToAim.c
#include<stdio.h>
#include<math.h>
int main()
{
float d,h,a;
scanf("%f%f",&d,&h);
a=atan(h/d);
a=a*(180.0/M_PI);
printf("%.2f\n",a);
}
Page No: 56
10
4
21.80
ID: 247Y1A6790
Test Case - 2
User Output
10
15
56.31
Test Case - 3
2024-2028-CSD-B
User Output
70.1
15.2
12.23
User Output
15.5
70.5
77.60
Test Case - 5
User Output
20.0
8.0
21.80
Exp. Name: A Treasure Hunter's Date: 2024-10-
S.No: 30
Page No: 57
Dilemma 13
Aim:
In a faraway kingdom, two treasure hunters named Alex and Bella embarked on a daring
ID: 247Y1A6790
quest to find valuable treasures. While exploring a mysterious cave, they stumbled upon
two treasure chests, each containing a unique gemstone. Curiosity took over, and they
decided to swap the gemstones inside the chests. However, a magical enchantment
prevented them from directly swapping the gemstones. To fulfill their quest and restore
the treasures to their rightful chests, Alex and Bella realized they could use a third
variable and arithmetic operations. Can you help them by writing a C program that takes
the values of the gemstones as input, and swap their values.
Input Format:
First line contains an integer a, representing the value of gemstone 1
Second line contains an integer b, representing the value of gemstone 2
2024-2028-CSD-B
Constraints:
1 <= a, b <= 104
Output Format:
Return the a, b values after swapping, separated by space.
Source Code:
#include<stdio.h>
int main()
{
int a,b,s;
scanf("%d%d",&a,&b);
s=a;
a=b;
b=s;
printf("%d %d",a,b);
}
User Output
6
5
65
15
65
23
20
10
6 5
65 15
65 23
20 10
User Output
User Output
User Output
Test Case - 4
Test Case - 3
Test Case - 2
Marri Laxman Reddy Institute of Technology and Management (Autonomous) 2024-2028-CSD-B ID: 247Y1A6790 Page No: 58
Exp. Name: Calculating Cylinder Surface Date: 2024-10-
S.No: 31
Page No: 59
Area 13
Aim:
Emily, a young architect, was working on designing a cylindrical water tank for a new
ID: 247Y1A6790
building. As she was finalizing the plans, she needed to calculate the surface area of the
cylinder to determine the amount of material required for its construction. However, she
was unsure of the exact formula and the steps involved in the calculation. Can you help
Emily by writing a C program that assists her in calculating the surface area of a cylinder?
Input Format:
• The first line contains a float value representing the radius of the cylinder.
• The second line contains a float value representing the height of the cylinder.
2024-2028-CSD-B
Output Format:
• A single float value with two decimal points representing the surface area of the
cylinder.
Constraints:
1 <= r, h <= 105
surfaceArea.c
#include<stdio.h>
#include<math.h>
int main()
{
float r,h,sa;
scanf("%f%f",&r,&h);
sa=2*M_PI*r*r+2*M_PI*r*h;
printf("%.2f",sa);
}
Page No: 60
User Output
2.68
8.1
ID: 247Y1A6790
181.52
Test Case - 2
User Output
16.2
7.21
2382.85
2024-2028-CSD-B
Test Case - 3
User Output
10.0
10.0
1256.64
User Output
1.5
2.5
37.70
Test Case - 5
User Output
15.62
9.5
2465.36
Date: 2024-10-
S.No: 32 Exp. Name: Polygon Area Calculator
Page No: 61
13
Aim:
Hemanth is an architect who wants to design a garden with a beautiful polygon-shaped
ID: 247Y1A6790
fountain at its canter. He needs to calculate the area of the polygon so that he can
determine the appropriate size for the garden. Help Hemanth by writing a C program that
calculates the area of a regular polygon when given the number of sides, N, and the
length of each side, L. UseM_PI as the constant for PI.
Input Format:
• First line of input contains an integer N representing the sides no of sides of the
polygon.
• Second line of input contains a floating value L representing the length of each
2024-2028-CSD-B
side.
Constraints:
• 1 <= N <= 103
• 1 <= L <= 105
Output Format:
areaOfFountain.c
#include<stdio.h>
#include<math.h>
int main()
{
int n;
float l,a;
scanf("%d%f",&n,&l);
a=(n*l*l)/(4*tan(M_PI/n));
printf("%.2f",a);
}
Page No: 62
User Output
4
5
ID: 247Y1A6790
25.00
Test Case - 2
User Output
10
2.5
48.09
2024-2028-CSD-B
Test Case - 3
User Output
20
2.3
167.00
User Output
20
10.0
3156.88
Test Case - 5
User Output
10
15.5
1848.53
Exp. Name: Calculating Cone Surface Date: 2024-10-
S.No: 33
Page No: 63
Area 13
Aim:
Prathima loves ice cream cones and wants to decorate the surface of her favorite ice
ID: 247Y1A6790
cream cone with colorful stickers. To know how many stickers she needs, she wants to
calculate the surface area of the cone. Help Prathima by writing a C program that
calculates the surface area of a cone when given the radius of the base, r, and the slant
height, L. Use π as 3.14.
Input Format:
First line of input contains an integer r representing the radius of base of the cone
Second line of input contains an integer L representing the slant height of the cone
2024-2028-CSD-B
Constraints:
1 <= r, L <= 105
Output Format:
Print the surface area of the cone
surfaceAreaOfCone.c
#include<stdio.h>
void main()
{
double r,l,sa;
scanf("%lf%lf",&r,&l);
sa=3.14*r*(r+l);
printf("%.2lf",sa);
}
User Output
2.65
9
96.94
Page No: 64
Test Case - 2
User Output
ID: 247Y1A6790
9
2.3
319.34
Test Case - 3
User Output
3.54
2024-2028-CSD-B
4.5
89.37
Test Case - 4
User Output
Test Case - 5
User Output
6.5
10.0
336.76
Date: 2024-10-
S.No: 34 Exp. Name: A Tale of Short and Tall
Page No: 65
13
Aim:
A short man takes n steps to a tall man's m steps. They both start out on the left foot.
ID: 247Y1A6790
How many steps do they have to take before they are both stepping out on the right foot
together?
Input Format:
First line of input contains an integer n representing the steps taken by short man
Second line of input contains an integer m representing the steps taken by tall man
Output Format:
Print the total no of steps that the short man and the tall man take so that they both can
step out on the right foot together.
Source Code:
2024-2028-CSD-B
noOfSteps.c
#include<stdio.h>
int gcd(int a,int b){
while (b!=0){
int temp=b;
Page No: 66
3
2
6
ID: 247Y1A6790
Test Case - 2
User Output
6
4
12
Test Case - 3
2024-2028-CSD-B
User Output
1
1
1
User Output
16
5
80
Test Case - 5
User Output
15
3
15
Date: 2024-10-
S.No: 35 Exp. Name: Dice Game Assessment
Page No: 67
25
Aim:
Chef and Chefina are playing with dice. In one turn, both of them roll their dice at once.
ID: 247Y1A6790
They consider a turn to be good if the sum of the numbers on their dice is greater than 6.
Given that in a particular turn, Chef and Chefina got X and Y on their respective dice,
find whether the turn was good.
Input Format:
• Input contains two space-separated integersX and Y - the numbers Chef and
Chefina got on their respective dice.
Constraints:
• 1 ≤ X, Y ≤ 100
2024-2028-CSD-B
Output format:
• Output a new line, YES, if the turn was good and NO otherwise.
Source Code:
dice.c
User Output
14
NO
NO
26
42
34
YES
YES
User Output
User Output
User Output
Test Case - 4
Test Case - 3
Test Case - 2
Marri Laxman Reddy Institute of Technology and Management (Autonomous) 2024-2028-CSD-B ID: 247Y1A6790 Page No: 68
Date: 2024-10-
S.No: 36 Exp. Name: Masterchef finals
Page No: 69
25
Aim:
Chef has been working hard to compete in MasterChef. He is ranked X out of all
ID: 247Y1A6790
contestants. However, only 10 contestants would be selected for the finals.
Input Format:
• Input contains one integerX - the current rank of Chef.
Constraints:
•1≤X ≤ 100
Output format:
2024-2028-CSD-B
• Output a new line, YES, if Chef made it to the top10 and NO otherwise.
Source Code:
chefRank.c
#include<stdio.h>
int main()
User Output
15
NO
1
NO
50
10
YES
YES
User Output
User Output
User Output
Test Case - 4
Test Case - 3
Test Case - 2
Marri Laxman Reddy Institute of Technology and Management (Autonomous) 2024-2028-CSD-B ID: 247Y1A6790 Page No: 70
Date: 2024-10-
S.No: 37 Exp. Name: Battery Health
Page No: 71
25
Aim:
Apple considers any iPhone with a battery health of 80 or above, to be in optimal
ID: 247Y1A6790
condition.
Given that your iPhone has X battery health, find whether it is in optimal condition or
not.
Input Format:
• Input contains an integerX - the battery health.
Constraints:
•0≤X ≤ 100
2024-2028-CSD-B
Output format:
• Output a new line, YES, if the battery is in optimal condition and NO otherwise.
Source Code:
battery.c
#include<stdio.h>
User Output
97
YES
NO
NO
10
80
42
YES
User Output
User Output
User Output
Test Case - 4
Test Case - 3
Test Case - 2
Marri Laxman Reddy Institute of Technology and Management (Autonomous) 2024-2028-CSD-B ID: 247Y1A6790 Page No: 72
Date: 2024-10-
S.No: 38 Exp. Name: Tom and Jerry Chase.
Page No: 73
25
Aim:
In a classic chase, Tom is running after Jerry as Jerry has eaten Tom's favourite food. Jerry
ID: 247Y1A6790
is running at a speed of X metres per second while Tom is chasing him at a speed of Y
metres per second. Determine whether Tom will be able to catch Jerry. Note that initially,
Jerry is not in the same position as Tom.
Input Format:
• The input contains two space-separated integersX and Y - the speeds of Jerry
and Tom respectively.
Constraints:
• 1 ≤ X, Y ≤ 10
2024-2028-CSD-B
Output Format:
• Return YES, if Tom will be able to catch Jerry. Otherwise, NO.
Source Code:
chase.c
#include<stdio.h>
User Output
23
YES
NO
NO
35
11
41
YES
User Output
User Output
User Output
Test Case - 4
Test Case - 3
Test Case - 2
Marri Laxman Reddy Institute of Technology and Management (Autonomous) 2024-2028-CSD-B ID: 247Y1A6790 Page No: 74
Exp. Name: Check whether Chef can
Date: 2024-10-
Page No: 75
S.No: 39 complete the entire textbook within a
25
given number of days
Aim:
ID: 247Y1A6790
Chef has started studying for the upcoming test. The textbook has N pages in total. Chef
wants to read at most X pages a day for Y days. Find out whether it is possible for Chef
to complete the whole book.
Input Format:
• The first line of input contains a single integer N , denoting the number of pages.
• The second line of input contains two space-separated integers X and Y ,
denoting the number of pages Chef can read in a day, and the number of days.
Constraints:
•1≤N ≤ 100
2024-2028-CSD-B
• 1 ≤ X, Y ≤ 10
Output Format:
• Return YES, if Chef can complete the whole book in the given time, and NO
otherwise.
Source Code:
#include<stdio.h>
int main()
{
int n;
int x,y;
scanf("%d%d%d",&n,&x,&y);
if(x*y>=n){
printf("YES\n");
}else{
printf("NO\n");
}
}
NO
NO
10
21
71
33
23
YES
YES
User Output
User Output
User Output
User Output
Test Case - 4
Test Case - 3
Test Case - 2
Marri Laxman Reddy Institute of Technology and Management (Autonomous) 2024-2028-CSD-B ID: 247Y1A6790 Page No: 76
Exp. Name: Chef's Race to the F1 Date: 2024-10-
S.No: 40
Page No: 77
Tournament 25
Aim:
Chef has finally got the chance of his lifetime to drive in the F1 tournament. But, there is
ID: 247Y1A6790
one problem. Chef did not know about the 107% rule and now he is worried whether he
will be allowed to race in the main event or not.
Given the fastest finish time as X seconds and Chef's finish time as Y seconds, determine
whether Chef will be allowed to race in the main event or not.
Note that, Chef will only be allowed to race if his finish time is within 107% of the fastest
finish time.
Input Format:
First line of input contains an integer X representing the fastest finish time
2024-2028-CSD-B
Second line of input contains an integer Y representing the Chef's finish time
Output Format:
Print Yes if Chef will be allowed to race in the main event, else printNo
Constraints:
1 <= X <= Y <= 200
Output:
No
Explanation: The fastest car finished in1 second. Thus, Chef should have finished on or
before1.07 seconds to ensure qualification but he finished in2 seconds. Hence, Chef will
not be allowed to race in the main event.
Source Code:
chefF1Tournament.c
#include<stdio.h>
Page No: 78
int main()
{
int x;
int y;
scanf("%d%d",&x,&y);
ID: 247Y1A6790
if(y<=x*1.07){
printf("Yes\n");
}else{
printf("No\n");
}
}
2024-2028-CSD-B
Test Case - 1
User Output
15
16
Yes
User Output
15
17
No
Test Case - 3
User Output
100
107
Yes
Test Case - 4
2
1
5
No
10
Yes
User Output
Test Case - 5
Marri Laxman Reddy Institute of Technology and Management (Autonomous) 2024-2028-CSD-B ID: 247Y1A6790 Page No: 79
Exp. Name: Can the Party Hall Fit Date: 2024-10-
S.No: 41
Page No: 80
Everyone 25
Aim:
Chef wants to host a party with a total of N people. However, the party hall has a capacity
ID: 247Y1A6790
of X people. Find whether Chef can host the party.
Input Format:
First line of input contains an integer N representing the no of people
Second line of input contains an integer X representing the capacity of hall
Output Format:
Print Yes, if Chef can host the party, otherwise print No
Constraints:
1 <= N, X <= 10000
2024-2028-CSD-B
Source Code:
PartyHallCapacity.c
#include<stdio.h>
int main()
{
User Output
2
5
Yes
Test Case - 2
Page No: 81
User Output
6
6
ID: 247Y1A6790
Yes
Test Case - 3
User Output
10
9
No
2024-2028-CSD-B
Test Case - 4
User Output
100
105
Yes
User Output
4
3
No
Exp. Name: One More Episode or the Date: 2024-11-
S.No: 42
Page No: 82
Exam 07
Aim:
Chef has to attend an exam that starts in X minutes, but of course, watching shows takes
ID: 247Y1A6790
priority. Every episode of the show that Chef is watching, is 24 minutes long. If he starts
watching a new episode now, will he finish watching it strictly before the exam starts?
Input Format:
Single line of input contains an integer X representing the time left for the test to start
Output Format:
Print Yes if Chef watch a new episode before the start time of the test, else print No
Constraints:
1 <= X <= 100
2024-2028-CSD-B
Source Code:
EpisodeOrExam.c
#include<stdio.h>
int main()
{
User Output
23
No
Test Case - 2
No
No
25
20
10
60
Yes
Yes
User Output
User Output
User Output
User Output
Test Case - 5
Test Case - 4
Test Case - 3
Marri Laxman Reddy Institute of Technology and Management (Autonomous) 2024-2028-CSD-B ID: 247Y1A6790 Page No: 83
Date: 2024-11-
S.No: 43 Exp. Name: Chef's Fare Choice
Page No: 84
07
Aim:
Chef has to travel to another place. For this, he can avail any one of two cab services.
ID: 247Y1A6790
• The first cab service charges X rupees.
• The second cab service charges Y rupees.
Chef wants to spend the minimum amount of money. Which cab service should Chef
take?
Input Format:
First line of input contains an integer X representing the price of first cab service
Second line of input contains an integer Y representing the price of second cab service
Output Format:
Print First if the first cab service charges are less or print Second if the second service
2024-2028-CSD-B
charges are less or print Any if the service charges of both the cabs is same.
Constraints:
1 <= X <= Y <= 500
Source Code:
minCabCost.c
Page No: 85
Test Case - 1
User Output
30
ID: 247Y1A6790
65
First
Test Case - 2
User Output
25
25
Any
2024-2028-CSD-B
Test Case - 3
User Output
50
12
Test Case - 4
User Output
10
20
First
Test Case - 5
User Output
20
10
Second
Date: 2024-11-
S.No: 44 Exp. Name: Chef's Instagram Filter
Page No: 86
07
Aim:
Chef categorizes an Instagram account as spam, if, the following count of the account is
ID: 247Y1A6790
more than 10 times the count of followers.
Given the following and follower count of an account as X and Y respectively, find
whether it is a spam account.
Input Format:
First line of input contains an integer X representing the following count
Second line of input contains an integer Y representing the followers count
Output Format:
Print Yes, if the account is spam and No otherwise
2024-2028-CSD-B
Constraints:
1 <= X, Y <= 100
Example:
Input:
Following count: 21
Output:
Yes
Explanation: The followers count is given as 2 and the following count is given as 21
which is more than 10 times of the followers count. So the account is a spam account.
Source Code:
SpamOrNot.c
#include<stdio.h>
Page No: 87
int main()
{
int X;
int Y;
scanf("%d%d",&X,&Y);
ID: 247Y1A6790
if(X>10*Y){
printf("Yes\n");
}else{
printf("No\n");
}
}
2024-2028-CSD-B
Test Case - 1
User Output
21
2
Yes
User Output
10
2
No
Test Case - 3
User Output
1
10
No
Test Case - 4
1
No
11
Yes
523
521
User Output
Test Case - 5
Marri Laxman Reddy Institute of Technology and Management (Autonomous) 2024-2028-CSD-B ID: 247Y1A6790 Page No: 88
Exp. Name: Chef's Remote Control Date: 2024-11-
S.No: 45
Page No: 89
Challenge 21
Aim:
Chef is watching TV. The current volume of the TV is X. Pressing the volume up button of
ID: 247Y1A6790
the TV remote increases the volume by 1 while pressing the volume down button
decreases the volume by 1. Chef wants to change the volume from X to Y. Find the
minimum number of button presses required to do so.
Input Format:
First line of input contains an integer X representing the initial volume
Second line of input contains an integer Y representing the final volume
Output Format:
Print the minimum number of times Chef has to press a button to change the volume
fromX toY.
2024-2028-CSD-B
Constraints:
1 <= X, Y <= 100
Source Code:
VolumeChange.c
User Output
50
54
4
Test Case - 2
Page No: 90
User Output
12
10
ID: 247Y1A6790
2
Test Case - 3
User Output
100
20
80
2024-2028-CSD-B
Test Case - 4
User Output
56
15
41
User Output
96
45
51
Date: 2024-11-
S.No: 46 Exp. Name: Connecting Towns
Page No: 91
21
Aim:
Cities on a map are connected by a number of roads. The number of roads between each
ID: 247Y1A6790
city is in an array and city 0 is the starting location. The number of roads from city 0 to
city 1 is the first value in the array, from city 1 to city 2 in the second, and so on.
How many paths are there from city 0 to the last city in the list, modulo 1234567?
Input Format:
First line of input contains an integer N representing the no of cities
Second line contains N - 1 space separated integers where ith integer denotes the no of
routes, Ni, from the city Ti to Ti+1
Output Format:
2024-2028-CSD-B
Print the total no of routes, modulo 1234567
Constraints:
2 < N <= 100
1 <= routes[i] <= 1000
Example:
Output:
3
Explanation: 1 route from T1 to T2, 3 routes from T2 to T3, hence only 3 routes.
Source Code:
connectingTowns.c
#include<stdio.h>
Page No: 92
#define MOD 1234567
int main() {
int N;
scanf("%d",&N);
int routes[N - 1];
ID: 247Y1A6790
for(int i = 0; i < N - 1; i++) {
scanf("%d",&routes[i]);
}
long long totalPaths = 1;
for(int i = 0; i < N - 1; i++) {
totalPaths = (totalPaths * routes[i]) % MOD;
}
printf("%lld\n",totalPaths);
return 0;
}
2024-2028-CSD-B
Execution Results - All test cases have succeeded!
Test Case - 1
User Output
Test Case - 2
User Output
4
222
8
Test Case - 3
User Output
4
213
6
1
3
5
24
11
1234
User Output
User Output
Test Case - 5
Test Case - 4
Marri Laxman Reddy Institute of Technology and Management (Autonomous) 2024-2028-CSD-B ID: 247Y1A6790 Page No: 93
Date: 2024-12-
S.No: 47 Exp. Name: Count the squares
Page No: 94
03
Aim:
Write a C program to determine the total number of squaresthat can be formed in a grid
ID: 247Y1A6790
of size M x N, where M and N are positive integers.
Input Format:
Single line of input contains two space separated integers representing M and N
respectively
Output Format:
Print the total no of squares present in the given M*N grid.
Constraints:
1 <= M, N <= 100
2024-2028-CSD-B
Source Code:
countingSquares.c
#include<stdio.h>
int main(){
int M,N;
User Output
22
5
Test Case - 2
2
1
8
20
12
11
43
32
User Output
User Output
User Output
User Output
Test Case - 5
Test Case - 4
Test Case - 3
Marri Laxman Reddy Institute of Technology and Management (Autonomous) 2024-2028-CSD-B ID: 247Y1A6790 Page No: 95
Exp. Name: Sum of digits of a five digit Date: 2024-12-
S.No: 48
Page No: 96
number. 03
Aim:
Given the five-digit number, print the sum of its digits.
ID: 247Y1A6790
Input Format:
• Input contains a single five digit number n
Constraints:
• 1000 ≤ n ≤ 99999
Output Format:
• Return the sum of individual digits, If the input is valid (i.e., n has exactly 5 digits)
• Return "Invalid input", If the input is invalid (i.e., n does not have exactly 5 digits)
Source Code:
2024-2028-CSD-B
sum.c
#include<stdio.h>
int main(){
int n,sum=0,c=0,t;
scanf("%d",&n);
Page No: 97
Test Case - 1
User Output
10564
ID: 247Y1A6790
16
Test Case - 2
User Output
12345
15
Test Case - 3
2024-2028-CSD-B
User Output
555555
Invalid input
User Output
1001
Invalid input
Date: 2024-12-
S.No: 49 Exp. Name: For loop in C
Page No: 98
03
Aim:
Write a program that takes two integers as input, start and end. The program should use
ID: 247Y1A6790
a for loop to iterate from start to end (both inclusive).
Input Format:
• Input contains two space-separated integers a and b, representing the start and
end values.
Constraints:
•1≤a < b ≤ 10
6
Output Format:
• Return a space-separated list of integers from a to b, If the input is valid (i.e., a is
2024-2028-CSD-B
less than or equal to b)
• Return "Invalid input", If the input is invalid (i.e., a is greater than b)
Source Code:
integers.c
#include<stdio.h>
Page No: 99
User Output
19
1 2 3 4 5 6 7 8 9
ID: 247Y1A6790
Test Case - 2
User Output
8 11
8 9 10 11
Test Case - 3
2024-2028-CSD-B
User Output
12 21
12 13 14 15 16 17 18 19 20 21
Test Case - 4
Aim:
Write a C program that takes the input for multiple test cases. For each test case, the
program should receive two integers, E and K , representing the energy at the lowest
ID: 247Y1A6790
trophic level and the energy reduction factor, respectively. The program should calculate
and display the maximum length of the food chain for each test case.
Input Format:
• The first line contains an integer N - the number of test cases. Then the test cases
follow.
• Each test case contains a single line of input, two integers E,K .
Constraints:
• 1 ≤ N ≤ 10 4
• 1 ≤ E, K ≤ 10 9
2024-2028-CSD-B
Output Format:
• Return the length of the food chain for each test case.
So the length of the food chain is2 since from the next level onwards0 units of energy will
be received.
#Testcase2: The food chain length is 1 because the initial energy (6) is less than the
energy reduction factor (7), so the chain ends immediately after one step.
• level 3 - units
5
= 2
2
• level 4 - 2
2
= 1 units
• level 5 - 1
2
= 0 units
So the length of the food chain is 4 since it is the last level to receive non-zero energy.
Source Code:
#include<stdio.h>
int main (){
int T;
scanf("%d", &T);
ID: 247Y1A6790
while (T--){
int energy, reductionFactor;
scanf("%d%d", &energy, &reductionFactor);
int length = 0;
while(energy > 0){
length++;
energy /= reductionFactor;
}
printf("%d\n", length);
}
2024-2028-CSD-B
return 0;
}
User Output
3
53
2
67
1
10 2
4
Test Case - 2
User Output
1
10 10
2
3
1
3
1
3
2
3
15
12
15 3
50 5
100 10
User Output
User Output
Test Case - 4
Test Case - 3
Marri Laxman Reddy Institute of Technology and Management (Autonomous) 2024-2028-CSD-B ID: 247Y1A6790 Page No: 102
Date: 2024-12-
S.No: 51 Exp. Name: Multiplication table
Aim:
Write a program in C that takes an integer, n, as input, representing the number of
multiplication tables to be generated. The program should output the multiplication table
ID: 247Y1A6790
for each number from 1 to n, up to a multiple of 10.
Input Format:
• A single integer n represents the number of times the multiplication table should
be printed.
Constraints:
•1≤n ≤ 20
Output Format:
2024-2028-CSD-B
• Multiplication tables from 1 to 10 for each number from 1 to n.
Source Code:
multiple.c
#include<stdio.h>
int main(){
User Output
2
1:
1 x 1 = 1
1 x 2 = 2
1 x 3 = 3
ID: 247Y1A6790
1 x 9 = 9
1 x 10 = 10
2:
2 x 1 = 2
2 x 2 = 4
2 x 3 = 6
2 x 4 = 8
2 x 5 = 10
2 x 6 = 12
2024-2028-CSD-B
2 x 7 = 14
2 x 8 = 16
2 x 9 = 18
2 x 10 = 20
Test Case - 2
ID: 247Y1A6790
3 x 2 = 6
3 x 3 = 9
3 x 4 = 12
3 x 5 = 15
3 x 6 = 18
3 x 7 = 21
3 x 8 = 24
3 x 9 = 27
3 x 10 = 30
2024-2028-CSD-B
4:
4 x 1 = 4
4 x 2 = 8
4 x 3 = 12
4 x 4 = 16
4 x 5 = 20
Test Case - 3
User Output
1
1:
1 x 1 = 1
1 x 2 = 2
1 x 3 = 3
1 x 4 = 4
1 x 5 = 5
1 x 6 = 6
1 x 7 = 7
1 x 8 = 8
1 x 10 = 10
User Output
3
ID: 247Y1A6790
1:
1 x 1 = 1
1 x 2 = 2
1 x 3 = 3
1 x 4 = 4
1 x 5 = 5
1 x 6 = 6
1 x 7 = 7
1 x 8 = 8
2024-2028-CSD-B
1 x 9 = 9
1 x 10 = 10
2:
2 x 1 = 2
2 x 2 = 4
2 x 3 = 6
2 x 4 = 8
Aim:
Alice, Bob, and Charlie have different preferences for numbers. Alice likes numbers that
are even and multiples of 7, while Bob prefers numbers that are odd and multiples of 9.
ID: 247Y1A6790
They have found a number, A, and the task is to determine who takes it home.
Write a program that takes an integer, A, as input and outputs the person who takes the
number home based on their preferences. If A is an even multiple of 7, Alice takes it
home. If A is an odd multiple of 9, Bob takes it home. If neither Alice nor Bob likes the
number, Charlie takes it home.
Input Format:
• Input consists of a single integer A.
Output Format:
• Return the name of the person (Alice, Bob, Charlie) based on the given conditions.
2024-2028-CSD-B
Source Code:
favNum.c
#include<stdio.h>
int main(){
int number;
User Output
14
Alice
63
15
27
Bob
Bob
Charlie
User Output
User Output
User Output
Test Case - 4
Test Case - 3
Test Case - 2
Marri Laxman Reddy Institute of Technology and Management (Autonomous) 2024-2028-CSD-B ID: 247Y1A6790 Page No: 108
Date: 2024-12-
S.No: 53 Exp. Name: Can Chef
Aim:
Chef owns a car that can run 15 kilometres using 1 litre of petrol. He wants to attend a
programming camp at DAIICT, which is a distance of Y kilometres from his house. Chef
ID: 247Y1A6790
currently has X litres of petrol in his car. The task is to determine whether Chef can
attend the event at DAIICT and return to his home with the given amount of petrol.
Note: Chef has to return back to home, so the total distance to be covered would be 2. Y
Input Format:
• The input contains two space-separated integers X and Y - the amount of petrol
in litre and the distance between Chef's house and DAIICT in kilometres,
respectively
Constraints:
• 1 ≤ x ≤ 10 2
2024-2028-CSD-B
Output Format:
• Return YES if it is possible for the chef to attend the event and return home, else,
return NO.
Source Code:
distance.c
User Output
NO
YES
YES
YES
8 30
12 40
10 50
15 200
User Output
User Output
User Output
Test Case - 4
Test Case - 3
Test Case - 2
Marri Laxman Reddy Institute of Technology and Management (Autonomous) 2024-2028-CSD-B ID: 247Y1A6790 Page No: 110
Exp. Name: Finding the Height of the Date: 2024-12-
S.No: 54
Aim:
Listen to this story: a boy and his father, a computer programmer, are playing with
wooden blocks. They are building a pyramid.Their pyramid is a bit weird, as it is actually a
ID: 247Y1A6790
pyramid-shaped wall - it's flat. The pyramid is stacked according to one simple principle:
each lower layer contains one block more than the layer above.The figure illustrates the
rule used by the builders:
2024-2028-CSD-B
Note: the height is measured by the number of fully completed layers - if the builders
don't have a sufficient number of blocks and cannot complete the next layer, they finish
their work immediately.
Constraints:
1 <= n <= 1000
Output Format:
Print the height of the pyramid
Example:
Input:
6
Output:
3
Explanation: Observe the given figure in the question description, with 6 blocks, we can
build a pyramid of height 3.
Source Code:
HeightOfPyramid.c
#include<stdio.h>
ID: 247Y1A6790
n -= blocksNeeded;
height++;
blocksNeeded++;
}
printf("%d\n", height);
return 0;
}
2024-2028-CSD-B
Execution Results - All test cases have succeeded!
Test Case - 1
User Output
6
Test Case - 2
User Output
100
13
Test Case - 3
User Output
1000
44
Test Case - 4
User Output
12
9
4
45
User Output
Test Case - 5
Marri Laxman Reddy Institute of Technology and Management (Autonomous) 2024-2028-CSD-B ID: 247Y1A6790 Page No: 113
Date: 2025-01-
S.No: 55 Exp. Name: Special Number
Aim:
Write a C program that allows the user to find a number such that its double is greater
than its half by a specified target difference value. If such a number exists, the program
ID: 247Y1A6790
should print Yes, otherwise, it should print No
Source Code:
SpecialNumber.c
#include<stdio.h>
int main()
{
static float x,y;
scanf("%f%f",&y ,&x);
2024-2028-CSD-B
if((2*x -x/2) == y)
printf("Yes\n");
else
printf("No\n");
}
User Output
45.0
30.0
Yes
Test Case - 2
User Output
135
90.0
Yes
Test Case - 3
No
No
No
15
30.0
60.0
50.0
30.5
45.0
User Output
User Output
User Output
Test Case - 5
Test Case - 4
Marri Laxman Reddy Institute of Technology and Management (Autonomous) 2024-2028-CSD-B ID: 247Y1A6790 Page No: 115
Exp. Name: Minimum Attendance Date: 2025-01-
S.No: 56
Aim:
Chef is a student at a university, and the university has a requirement that students must
be present for at least 75% of the working days in a semester to pass. The semester has a
ID: 247Y1A6790
total of 120 working days. Chef has been taking a lot of holidays and is worried about
meeting the attendance requirement. The information about the days Chef has attended
or been absent is given as a sequence of N bits: B1, B2, ..., BN. If Bi = 0, it means Chef was
absent on the ith day, and if Bi = 1, it means Chef was present on that day. The task is to
determine if Chef can pass the attendance requirement by the end of the semester.
Write a program that takes an integer N as input, followed by a sequence of N bits, and
outputs whether Chef can hope to pass the attendance requirement or not.
Input Format:
2024-2028-CSD-B
First line of input contains an integer N representing the no of days till now
Second line of input contains a string B of length N where Bi represents the status of the
ith day.
Output Format:
Print"Yes" if Chef can pass the attendance requirement and "N0" if not
Example:
Input:
50
00000000000000000000000000000000000000000000000000
Output:
No
Explanation:
Even if Chef attends all the remaining 70 days, he'll only have an attendance percentage
of70/120 =58.33% which is less than75%.
Source Code:
attendanceRequirement.c
#include<stdio.h>
ID: 247Y1A6790
char s[n];
scanf("%s",s);
for(int i=0;i<n;i++)
{
r=s[i];
if(r==48)
a++;
}
if(a>30)
printf("No\n");
2024-2028-CSD-B
else
printf("Yes\n");
}
User Output
50
00000000000000000000000000000000000000000000000000
No
Test Case - 2
User Output
2
01
Yes
Test Case - 3
User Output
10
0101011010
Test Case - 4
ID: 247Y1A6790
User Output
45
000000000000000000000000000000000000000000000
No
Test Case - 5
User Output
2024-2028-CSD-B
60
000000000000000000000000000000000000000000000000000000000000
No
Aim:
Write a C program for printing the number pattern for given N
ID: 247Y1A6790
Example:
N=5
Output:
12345
1234
123
12
1
Source Code:
2024-2028-CSD-B
numberPattern.c
#include<stdio.h>
int main()
{
static int n;
User Output
2
1 2
1
1
1
1
5
1 2
1 2 3
1 2 3 4
1 2 3 4 5
User Output
User Output
Test Case - 3
Test Case - 2
Marri Laxman Reddy Institute of Technology and Management (Autonomous) 2024-2028-CSD-B ID: 247Y1A6790 Page No: 120
Date: 2025-01-
S.No: 59 Exp. Name: Decrement OR Increment
Aim:
Write a C program to obtain a number N and increment its value by 1 if the number is
divisible by 4 otherwise decrement its value by 1.
ID: 247Y1A6790
Source Code:
IncrementOrDecrement.c
#include<stdio.h>
int main()
{
int n;
scanf("%d",&n);
if(n%4==0)
2024-2028-CSD-B
{
n++;
}
else
{
n--;
}
User Output
5
4
Test Case - 2
User Output
100
101
17
16
229
241
230
240
User Output
User Output
User Output
Test Case - 5
Test Case - 4
Test Case - 3
Marri Laxman Reddy Institute of Technology and Management (Autonomous) 2024-2028-CSD-B ID: 247Y1A6790 Page No: 122
Exp. Name: Incrementing the integer by Date: 2024-12-
S.No: 60
Aim:
Given a large integer represented as an integer array of digits, where each digits[i] is the
i-th digit of the integer, ordered from most significant to least significant in left-to-right
ID: 247Y1A6790
order (without any leading zeros). Implement a program to increment the large integer
by one and return the resulting array of digits.
Input Format:
• The first line contains an integer 'digitsSize', representing the number of digits.
• The second line contains space-separated integers (digits) representing the digits
of the large integer.
Constraints:
• 1 ≤ digitsSize ≤ 100
• 0 ≤ digits[i] ≤ 9
2024-2028-CSD-B
• digits do not contain any leading 0's.
Output Format:
• Return comma-separated digits of incremented large integer.
increment.c
#include <stdio.h>
ID: 247Y1A6790
// Read the digits of the large number
for (int i = 0; i < digitsSize; i++) {
scanf("%d", &digits[i]);
}
2024-2028-CSD-B
break; // No carry, no need to continue
}
if (digits[i] == 10) {
digits[i] = 0; // Set the digit to 0 and carry over 1
ID: 247Y1A6790
Execution Results - All test cases have succeeded!
Test Case - 1
User Output
4
4321
2024-2028-CSD-B
4,3,2,2
Test Case - 2
User Output
1
Test Case - 3
User Output
3
123
1,2,4
Test Case - 4
User Output
3
527
5,2,8
Exp. Name: Determine the number of Date: 2024-12-
S.No: 61
Aim:
Chef has set a target to solve at least 10 problems every week for a duration of 4 weeks.
Your task is to determine the number of weeks in which the Chef met his target.
ID: 247Y1A6790
Input Format:
• The input consists of 4 integers representing the number of problems Chef solved
in each week (P 1, P 2, P 3, and P 4).
Output Format:
• The output should be a single integer indicating the count of weeks where Chef
solved at least 10 problems.
2024-2028-CSD-B
3
Explanation: Chef solved at least 10 problems in the first, second and fourth weeks. He
failed to solve at least 10 problems in the third week. Hence, the number of weeks in
which Chef met his target is 3.
Source Code:
week.c
ID: 247Y1A6790
Test Case - 2
User Output
2 3 1 10
1
Test Case - 3
2024-2028-CSD-B
User Output
12 100 99 11
4
Test Case - 4
Aim:
Chef recently revamped its practice page to make it easier for users to identify the next
problems they should solve by introducing some new features:
ID: 247Y1A6790
• Recent Contest Problems - contains only problems from the last 2 contests
• Separate Un-Attempted, Attempted, and All tabs.
• Problem Difficulty Rating - the Recommended dropdown menu has various
difficulty ranges so that you can attempt the problems most suited to your
experience
• Popular Topics and Tags
Like most users, Chef didn’t know that he could add problems to a personal to-do list by
clicking on the magic '+' symbol on the top-right of each problem page. But once he
found out about it, he went crazy and added loads of problems to his to-do list without
looking at their difficulty rating. Chef is a beginner and should ideally try and solve only
2024-2028-CSD-B
problems with difficulty rating strictly less than 1000.
Given a list of difficulty ratings for problems in the Chef’s to-do list, please help him
identify how many of those problems Chef should remove from his to-do list, so that he
is only left with problems of difficulty rating less than 1000.
Input Format:
which are the difficulty ratings for each problem in the to-do list.
Constraints:
•1≤N ≤ 1000
•1≤D i ≤ 5000
Output Format:
• Return the number of problems that Chef will have to remove so that all remaining
problems have a difficulty rating strictly less than 1000
Source Code:
PracticeProgram.c
#include<stdio.h>
ID: 247Y1A6790
for (int i = 0; i < n; i++){
scanf("%d", &difficulty);
if(difficulty >= 1000){
count++;
}
}
printf("%d\n", count);
return 0;
}
2024-2028-CSD-B
Execution Results - All test cases have succeeded!
Test Case - 1
User Output
Test Case - 2
User Output
3
800 1200 900
1
Test Case - 3
User Output
4
999 1000 1001 1002
3
1
5
1 2 2 2 5000
User Output
Test Case - 4
Marri Laxman Reddy Institute of Technology and Management (Autonomous) 2024-2028-CSD-B ID: 247Y1A6790 Page No: 130
Date: 2024-12-
S.No: 63 Exp. Name: Maximize the profit
Aim:
You are given an array price where prices[i] is the price of a given stock on the ith day. You
want to maximize your profit by choosing a single day to buy one stock and choosing a
ID: 247Y1A6790
different day in the future to sell that stock.
Input format:
• The first line contains an integer (pricesSize) representing the number of days.
• The second line contains space-separated (pricesSize) integers representing the
stock prizes for each day.
Constraints:
• 1 ≤ pricesSize ≤ 10 5
• 0 ≤ prices[i] ≤ 10 4
2024-2028-CSD-B
Output Format:
• Return the maximum profit you can achieve from this transaction. If you cannot
achieve any profit, return 0.
profit.c
#include <stdio.h>
int prices[pricesSize];
ID: 247Y1A6790
// Read stock prices for each day
for (int i = 0; i < pricesSize; i++) {
scanf("%d", &prices[i]);
}
2024-2028-CSD-B
for (int i = 1; i < pricesSize; i++) {
// Calculate potential profit if sold on the current day
int potential_profit = prices[i] - min_price;
return 0;
}
User Output
5
3
5
0
2
4
6
5
16
1234
76431
715364
User Output
User Output
User Output
Test Case - 4
Test Case - 3
Test Case - 2
Marri Laxman Reddy Institute of Technology and Management (Autonomous) 2024-2028-CSD-B ID: 247Y1A6790 Page No: 133
Date: 2024-12-
S.No: 64 Exp. Name: Find the odd one out
Aim:
Given a non-empty array of integers nums, every element appears twice except for one.
Find that single one.
ID: 247Y1A6790
You must implement a solution with a linear runtime complexity and use only constant
extra space.
Input Format:
• The first line contains an integer numsSize representing the number of elements in
the array.
• The second line contains numsSize integers representing the elements of the array.
Constraints:
2024-2028-CSD-B
• 1 ≤ nums.size ≤ 10 4
• −10 ≤ nums[i] ≤ 10
4 4
• Each element in the array appears twice except for one element which appears
only once.
Output Format:
• Return an integer which is the single number in the array.
element.c
#include<stdio.h>
int main()
{
int numsSize;
scanf("%d", &numsSize);
int nums[numsSize];
for(int i=0; i<numsSize; i++){
scanf("%d", &nums[i]);
}
int result=0;
for (int i=0; i< numsSize; i++){
result ^= nums[i];
}
printf("%d\n", result);
return 0;
}
Execution Results - All test cases have succeeded!
User Output
3
ID: 247Y1A6790
221
1
Test Case - 2
User Output
5
41212
4
2024-2028-CSD-B
Test Case - 3
User Output
1
1
Test Case - 4
User Output
5
66474
7
Date: 2024-12-
S.No: 65 Exp. Name: Majority Element
Aim:
Given an array nums of size n, return the majority element. The majority element is the
element that appears more than ⌊n/2⌋ times. You may assume that the majority element
ID: 247Y1A6790
always exists in the array.
Input Format:
• The first line contains an integer n representing the number of elements in the
array.
• The second line contains n integers representing the elements of the array.
Output Format:
• An integer representing the majority element that appears more than ⌊n/2⌋ times
in the array.
Source Code:
2024-2028-CSD-B
majority.c
#include<stdio.h>
int main()
{
int n;
User Output
3
ID: 247Y1A6790
323
3
Test Case - 2
User Output
7
2211122
2
2024-2028-CSD-B
Test Case - 3
User Output
2
33
Test Case - 4
User Output
5
66474
4
Date: 2024-12-
S.No: 66 Exp. Name: Small Factorials
Aim:
Write a C program to calculate the factorial of small positive integers
ID: 247Y1A6790
Input Format:
Single line of input contains an integer N representing the value to find the factorial
Output Format:
Print the factorial result of N
Source Code:
factorial.c
2024-2028-CSD-B
#include<stdio.h>
int main()
{
int N;
scanf("%d", &N);
long long int result = 1;
for (int i = 1; i <= N; i++){
User Output
2
2
Test Case - 2
User Output
3
1
6
1
5
4
24
120
User Output
User Output
User Output
Test Case - 5
Test Case - 4
Test Case - 3
Marri Laxman Reddy Institute of Technology and Management (Autonomous) 2024-2028-CSD-B ID: 247Y1A6790 Page No: 139
Date: 2024-12-
S.No: 67 Exp. Name: On a Way to Market
Aim:
You're on your way to the market and meet a man who has multiple wives. Each wife has
x no of bags, and each bag contains y number of dogs, with each dog having z no of
ID: 247Y1A6790
puppies. Write a C program that takes input for the number of wives, bags per wife, dogs
per bag, and puppies per dog. Calculate and display the total number of living beings
(not including yourself) that are going to the market.
Input Format:
First line of input contains the number of wives
Second line of input contains the number of bags per wife
Third line of input contains the number of dogs per bag
Fourth line of input contains the number of puppies per dog
2024-2028-CSD-B
Output Format:
Print the total no of living beings going to the market
Constraints:
1 <= no of wives <= 10
1 <= x <= 10
0 <= y, z <= 10
NoOfBeings.c
#include<stdio.h>
int main ()
{
int w, x, y, z;
scanf("%d", &w);
scanf("%d", &x);
scanf("%d", &y);
scanf("%d", &z);
int totalLivingBeings = w + (w * x * y) + (w * x * y * z);
printf("%d\n", totalLivingBeings+1);
return 0;
}
ID: 247Y1A6790
4
325
Test Case - 2
User Output
1
2
2024-2028-CSD-B
1
9
22
Test Case - 3
Test Case - 4
User Output
3
1
1
2
13
3
1
2
1
10
User Output
Marri Laxman Reddy Institute of Technology and Management (Autonomous) 2024-2028-CSD-B ID: 247Y1A6790 Page No: 142
Date: 2024-12-
S.No: 68 Exp. Name: Pretty Numbers
Aim:
Lahya likes the number 239. Therefore, she considers a number pretty if its last digit is 2
or 3 or 9. Lahya wants to watch the numbers between L and R (both inclusive), so she
ID: 247Y1A6790
asked you to determine how many pretty numbers are in this range. Can you help her?
Input Format:
• A single line of input contains two space-separated integersL andR
Output Format:
• Print the total no of Pretty numbers between L and R
Constraints:
• 1 <= L <= R <=105
2024-2028-CSD-B
Source Code:
CountingPrettyNums.c
#include<stdio.h>
int main ()
{
User Output
1 11
3
User Output
ID: 247Y1A6790
11 35
8
Test Case - 3
User Output
1 100
30
2024-2028-CSD-B
Test Case - 4
User Output
100 599
150
User Output
1 599
180
Date: 2024-12-
S.No: 69 Exp. Name: What is your Score?
Aim:
You are participating in a contest which has 11 problems (numbered 1 through 11). The
first eight problems (i.e. problems 1,2,…,8) are scorable, while the last three problems (9,10
ID: 247Y1A6790
and 11) are non-scorable - this means that any submissions you make on any of these
problems do not affect your total score.
Your total score is the sum of your best scores for all scorable problems. That is, for each
scorable problem, you look at the scores of all submissions you made on that problem
and take the maximum of these scores (or 0 if you didn't make any submissions on that
problem); the total score is the sum of the maximum scores you took.
You know the results of all submissions you made. Calculate your total score.
Input Format:
2024-2028-CSD-B
First line of input contains a single integerN denoting the number of submissions you
made
Next N lines follow. For eachi (1 ≤ i ≤ N), theith of these lines contains two space-
separated integerspiandsi, denoting that youri-th submission was on problempi and it
received a scoresi
Output Format:
Constraints:
1 <= N <= 1000
1 <= pi<= 11 for each validi
0 <= si <= 100 for each validi
Source Code:
TotalScore.c
#include <stdio.h>
ID: 247Y1A6790
int max_scores[8] = {0}; // Initialize all scores to 0
2024-2028-CSD-B
max_scores[index] = si; // Update the max score for this problem
}
}
}
// Calculate the total score as the sum of max scores for problems 1
through 8
return 0;
}
User Output
1
11 1
0
Test Case - 2
ID: 247Y1A6790
80
2 15
89
54
Test Case - 3
User Output
2024-2028-CSD-B
3
80
2 15
2 46
46
User Output
1
100 125
0
Test Case - 5
User Output
3
100 200
12 15
12 156
0
Date: 2024-12-
S.No: 70 Exp. Name: Matrix Multiplication
Aim:
Write a C program to help Joe and Lilly multiply two matrices, A and B. The program
should take input for multiple test cases. For each test case, the program should read the
ID: 247Y1A6790
dimensions and values of matrices A and B. If the multiplication is possible, the program
should print the output matrix values. If the multiplication is not possible, the program
should print "IMPOSSIBLE"
Input Format:
• The first line contains a number, t, denoting the number of test cases.
• Next line is to take the no.of rows & columns of matrix A separated with space.
• After that take the matrix values of A separated with space.
• Next line is to take the no.of rows & columns of matrix B separated with space.
• After that take the matrix values of B separated with space.
2024-2028-CSD-B
Constraints:
• 1 ≤ t ≤ 100
• 1 ≤ A[i,j] ≤ 1000
• 1 ≤ B[i,j] ≤ 1000
Output Format:
• If the multiplication is possible, then print the output matrix values separated with
space.
Matrix.c
#include <stdio.h>
ID: 247Y1A6790
for (int k = 0; k < A_cols; k++) {
C[i][j] += A[i][k] * B[k][j];
}
}
}
}
int main() {
int t;
scanf("%d", &t);
while (t--) {
2024-2028-CSD-B
int A_rows, A_cols, B_rows, B_cols;
int A[100][100], B[100][100], C[100][100];
scanf("%d %d\n", &A_rows, &A_cols);
for (int i = 0; i < A_rows; i++) {
for (int j = 0; j < A_cols; j++) {
scanf("%d", &A[i][j]);
}
User Output
3
ID: 247Y1A6790
22
1234
22
1111
3 3
7 7
13
123
32
2024-2028-CSD-B
100110
4 2
13
345
12
89
Test Case - 2
User Output
1
23
123456
33
7 8 9 10 11 12 13 14 15
66 72 78
156 171 186
Test Case - 3
User Output
1
32
76 82
292 316
184 199
123456789
10 11 12 13 14 15
Marri Laxman Reddy Institute of Technology and Management (Autonomous) 2024-2028-CSD-B ID: 247Y1A6790 Page No: 151
Date: 2024-12-
S.No: 71 Exp. Name: Search a given Matrix
Aim:
You are given an m x n integer matrix with the following two properties:
• Each row is sorted in non-decreasing order.
ID: 247Y1A6790
• The first integer of each row is greater than the last integer of the previous row.
Input Format:
• The first line contains two integers, m and n, representing the number of rows and
columns of the matrix.
• The following m lines each contain n integers, representing the elements of the
matrix row-wise.
• The last line contains an integer, target, representing the target element to search
2024-2028-CSD-B
for in the matrix.
Constraints:
• m == matrix.length
• n == matrix[i].length
• 1 <= m, n <= 100
• -104 <= matrix[i][j], target <= 104
Output Format:
Matrix.c
#include <stdio.h>
ID: 247Y1A6790
if (mid_val == target) {
return 1; // target found
} else if (mid_val < target) {
left = mid + 1; // search in the right half
} else {
right = mid - 1; // search in the left half
}
}
return 0; // target not found
2024-2028-CSD-B
}
int main() {
int m, n, target;
return 0;
}
Execution Results - All test cases have succeeded!
User Output
34
ID: 247Y1A6790
1357
10 11 16 20
23 30 34 60
3
true
Test Case - 2
User Output
2024-2028-CSD-B
34
1357
10 11 16 20
23 30 34 60
13
false
User Output
22
12
34
4
true
Test Case - 4
User Output
23
123
456
0
false
Marri Laxman Reddy Institute of Technology and Management (Autonomous) 2024-2028-CSD-B ID: 247Y1A6790 Page No: 155
Date: 2024-12-
S.No: 72 Exp. Name: Richest Customer Wealth
Aim:
You are given an m x n integer grid accounts where accounts[i][j] is the amount of money
the ith customer has in the jth bank. Return the wealth that the richest customer has. A
ID: 247Y1A6790
customer's wealth is the amount of money they have in all their bank accounts. The
richest customer is the customer that has the maximum wealth.
Input Format:
• First line,the number of customers
• Second line, the number of banks
• Third line, the wealth of each customer in each bank, and the output format
provides the maximum wealth among all customers.
Constraints:
• m == accounts.length
2024-2028-CSD-B
• n == accounts[i].length
• 1 <= m, n <= 50
• 1 <= accounts[i][j] <= 100
Output Format:
• Return the maximum wealth among all customers.
Source Code:
ID: 247Y1A6790
// Sum up the wealth for the current customer
for (int j = 0; j < n; j++) {
customerWealth += accounts[i][j];
}
2024-2028-CSD-B
}
return maxWealth;
}
int main() {
int m, n;
return 0;
}
Execution Results - All test cases have succeeded!
User Output
2
ID: 247Y1A6790
2
15
25
7
Test Case - 2
User Output
3
2024-2028-CSD-B
2
15
73
35
10
User Output
2
3
234
567
18
Test Case - 4
User Output
1
1
100
100
Date: 2024-12-
S.No: 73 Exp. Name: Matrix Diagonal Sum
Aim:
Given a square matrix mat, return the sum of the matrix diagonals.
ID: 247Y1A6790
Only include the sum of all the elements on the primary diagonal and all the elements on
the secondary diagonal that are not part of the primary diagonal.
Example:
2024-2028-CSD-B
Input:
3 size of the matrix. i.e., 3 × 3 Matrix
123 Subsequent lines contain matrix elements separated by spaces, representing a
utput:
O
25 Sum of the primary diagonal and the secondary diagonal (excluding the
elements that are part of the primary diagonal).
Explanation:
Diagonals sum: 1 + 5 + 9 + 3 + 7 = 25
Notice that element mat[1][1] = 5 is counted only once.
Constraints:
• n == mat.length == mat[i].length
• 1 <= n <= 100
• 1 <= mat[i][j] <= 100
Source Code:
diagonalSum.c
#include <stdio.h>
ID: 247Y1A6790
// Add the element from the secondary diagonal
sum += mat[i][n - 1 - i];
}
// If the matrix size is odd, subtract the center element once (it was
counted twice)
if (n % 2 != 0) {
sum -= mat[n / 2][n / 2];
}
2024-2028-CSD-B
return sum;
}
int main() {
int n;
return 0;
}
ID: 247Y1A6790
789
25
Test Case - 2
User Output
4
1111
2024-2028-CSD-B
1111
1111
1111
8
Test Case - 3
Test Case - 4
User Output
5
10001
02020
00300
02020
10001
15
Exp. Name: Multiplication of two Date: 2024-12-
S.No: 74
Aim:
Write a program to perform matrix multiplication. If Multiplication cannot be done for the
given matrices, then print "Not Possible"
ID: 247Y1A6790
Input Format:
• First line of input contains two space separated integers, no of rows (r1) and
columns (c1) of matrix 1
• Next r1 lines contains c1 no of elements of matrix 1, separated by space
• Next line of input contains two space separated integers, no of rows (r2) and
columns (c2) of matrix 2
• Next r2 lines contains c2 no of elements of matrix 2, separated by space
Output Format:
2024-2028-CSD-B
• Print the result after multiplying the two matrices, if multiplication is not possible,
print "Not Possible"
Constraints:
• 1 <= r1, c1, r2, c2 <= 10
• 0 <= matrix1[i], matrix2[i] <= 100
Source Code:
ID: 247Y1A6790
}
for (int i = 0; i < r1; i++) {
for (int j = 0; j < c2; j++) {
C[i][j] = 0;
}
}
for (int i = 0; i < r1; i++) {
for (int j = 0; j < c2; j++) {
for (int k = 0; k < c1; k++) {
C[i][j] += A[i][k] * B[k][j];
2024-2028-CSD-B
}
}
}
for (int i = 0; i < r1; i++) {
for (int j = 0; j < c2; j++) {
printf("%d ", C[i][j]);
}
ID: 247Y1A6790
Test Case - 1
User Output
22
12
34
22
12
2024-2028-CSD-B
34
7 10
15 22
Test Case - 2
Test Case - 3
User Output
22
11 22
33 44
22
33 44
847 1210
Test Case - 4
ID: 247Y1A6790
User Output
23
123
456
32
12
34
56
2024-2028-CSD-B
22 28
49 64
Test Case - 5
User Output
Aim:
Given two sorted arrays arr1 and arr2 of size m and n respectively, return the median of
the two sorted arrays.
ID: 247Y1A6790
Input Format:
First line of input contains an integer m
Second line of input contains m space separated integer elements of arr1
Third line of input contains an integer n
Fourth line of input contains n space separated integer elements of arr2
Output Format:
Print the median of the given two sorted arrays
2024-2028-CSD-B
Constraints:
1 <= m, n <= 1000
0 <= arr1[i], arr2[i] <= 10000
1 <= m + n <= 2000
Source Code:
MedianofTwoArrays.c
ID: 247Y1A6790
merged[k++] = arr1[i++];
} else {
merged[k++] = arr2[j++];
}
}
// If any elements are left in arr1
while (i < m) {
merged[k++] = arr1[i++];
}
// If any elements are left in arr2
2024-2028-CSD-B
while (j < n) {
merged[k++] = arr2[j++];
}
// Calculate the median
int totalLength = m + n;
if (totalLength % 2 == 1) {
// Odd length: The median is the middle element
ID: 247Y1A6790
Execution Results - All test cases have succeeded!
Test Case - 1
User Output
2
13
1
2
2024-2028-CSD-B
2.00000
Test Case - 2
User Output
Test Case - 3
User Output
3
568
4
1 9 15 20
8.00000
Test Case - 4
User Output
5
4
3
5
369
4.00000
7.50000
4 6 8 12
12345
3 6 9 12 15
User Output
Test Case - 5
Marri Laxman Reddy Institute of Technology and Management (Autonomous) 2024-2028-CSD-B ID: 247Y1A6790 Page No: 169
Date: 2024-12-
S.No: 76 Exp. Name: Minimum Path Sum
Aim:
Given a m x n grid filled with non-negative numbers, find a path from top left to bottom
right, which minimizes the sum of all numbers along its path.
ID: 247Y1A6790
Note: You can only move either down or right at any point in time.
Input Format:
First line of input contains two space separated integers m, n, representing the size of
grid
Next m lines contain n space separated elements of the grid
Output Format:
Print the minimal sum of all numbers along the path
2024-2028-CSD-B
Constraints:
1 <= m, n <= 200
0 <= grid[i][j] <= 200
Example:
Input:
Output:
7
Explanation:
Source Code:
MinimumPathSum.c
The Path with minimum sum is: 1 -> 3 -> 1 -> 1 -> 1 which is equal to 7
Marri Laxman Reddy Institute of Technology and Management (Autonomous) 2024-2028-CSD-B ID: 247Y1A6790 Page No: 171
#include <stdio.h>
ID: 247Y1A6790
// Initialize first row (can only come from the left)
for (int j = 1; j < n; j++) {
dp[0][j] = dp[0][j - 1] + grid[0][j];
}
// Initialize first column (can only come from the top)
for (int i = 1; i < m; i++) {
dp[i][0] = dp[i - 1][0] + grid[i][0];
}
// Fill the rest of the dp table
for (int i = 1; i < m; i++) {
2024-2028-CSD-B
for (int j = 1; j < n; j++) {
dp[i][j] = grid[i][j] + (dp[i - 1][j] < dp[i][j - 1] ? dp[i - 1][j] :
dp[i][j -
1]);
}
}
// The bottom-right corner holds the result
User Output
33
ID: 247Y1A6790
131
151
421
7
Test Case - 2
User Output
33
2024-2028-CSD-B
132
473
645
14
User Output
44
3310
3033
2303
0333
15
Test Case - 4
User Output
43
311
251
155
211
21
10
33
789
456
123
User Output
Test Case - 5
Marri Laxman Reddy Institute of Technology and Management (Autonomous) 2024-2028-CSD-B ID: 247Y1A6790 Page No: 174
Date: 2024-12-
S.No: 77 Exp. Name: Majority Element
Aim:
Given an array arr of size n, return the majority element. The majority element is the
element that appears more than [ n / 2 ] times. You may assume that the majority
ID: 247Y1A6790
element always exists in the array.
Input Format:
First line of input contains an integer n
Second line of input contains n no of space separated elements of the array
Output Format:
Print the majority element of the array
Constraints:
2024-2028-CSD-B
1 <= n <= 5 * 104
0 <= arr[i] <= 109
Source Code:
MajorityElement.c
ID: 247Y1A6790
candidate = arr[i];
count = 1;
} else if (arr[i] == candidate) {
count++;
} else {
count--;
}
}
2024-2028-CSD-B
return candidate;
}
int main() {
int n;
scanf("%d", &n); // Read the number of elements in the array
int arr[n];
return 0;
}
User Output
3
323
3
Test Case - 2
ID: 247Y1A6790
Test Case - 3
User Output
8
12112121
1
2024-2028-CSD-B
Test Case - 4
User Output
10
5651585455
5
User Output
7
12 12 12 45 59 12 1
12
Date: 2024-12-
S.No: 78 Exp. Name: Search Insert Position
Aim:
Given a sorted array of distinct integers and a target value, return the index if the target is
found. If not, return the index where it would be if it were inserted in order.
ID: 247Y1A6790
Input Format:
First line of input contains an integer n
Second line of input contains n no of space separated elements of the sorted array
Third line of input contains an integer representing the target value
Output Format:
Print the index if the target value is found. If not, print the index where it would be if it
were inserted in order.
2024-2028-CSD-B
Constraints:
1 <= n <= 104
0 <= arr[i] <= 109
Source Code:
SearchInsertPosition.c
ID: 247Y1A6790
if (arr[mid] == target) {
return mid; // Target found, return the index
} else if (arr[mid] < target) {
left = mid + 1; // Target is on the right side
} else {
right = mid - 1; // Target is on the left side
}
}
2024-2028-CSD-B
return left;
}
int main() {
int n;
scanf("%d", &n); // Read the size of the array
int arr[n];
int target;
scanf("%d", &target); // Read the target value
return 0;
}
User Output
4
1356
Test Case - 2
ID: 247Y1A6790
User Output
4
1356
2
1
Test Case - 3
2024-2028-CSD-B
User Output
4
1356
7
4
User Output
5
13579
9
4
Test Case - 5
User Output
5
13579
8
4
Exp. Name: Count the Negative Date: 2024-12-
S.No: 79
Aim:
Given a matrix m × n grid which is sorted in non-increasing order both row-wise and
column-wise, return the number of negative numbers in the grid.
ID: 247Y1A6790
Input Format:
• The first line of input contains two space-separated integers m and n respectively
• Next m lines contain n space-separated integers of the grid in non-increasing
order
Output Format:
• Print the number of negative numbers in the grid
Constraints:
2024-2028-CSD-B
• 1 ≤ m, n ≤ 100
Source Code:
CountNegativeNumbers.c
ID: 247Y1A6790
for(col=0;col<n;col++){
if (grid[row][col] < 0) {
// If the current element is negative, count all the negative numbers
in this row
count += 1; // All elements in the row to the left are negative
// Move to the next row
}
}
}
2024-2028-CSD-B
return count;
}
int main() {
int m, n;
scanf("%d %d", &m, &n); // Input the number of rows and columns
int grid[m][n];
return 0;
}
ID: 247Y1A6790
1 1 -1 -2
-1 -1 -2 -3
8
Test Case - 2
User Output
22
2024-2028-CSD-B
32
10
0
Test Case - 3
Test Case - 4
User Output
33
15 14 13
8 -10 -15
-4 -16 -18
5
0
22
15 13
63 60
User Output
Marri Laxman Reddy Institute of Technology and Management (Autonomous) 2024-2028-CSD-B ID: 247Y1A6790 Page No: 184
Date: 2024-12-
S.No: 80 Exp. Name: Strong Password
Aim:
Louise joined a social networking site to stay in touch with her friends. The signup page
required her to input a name and a password. However, the password must be strong.
ID: 247Y1A6790
The website considers a password to be strong if it satisfies the following criteria:
• Its length is at least 6.
• It contains at least one digit.
• It contains at least one lowercase English character.
• It contains at least one uppercase English character.
• It contains at least one special character. The special characters are: !@#$%^&*()-
+
She typed a random string of length nin the password field but wasn't sure if it was
strong. Given the string she typed, can you find the minimum number of characters she
must add to make her password strong?
2024-2028-CSD-B
Note: Here's the set of types of characters in a form you can paste in your solution:
numbers = "0123456789"
lower_case = "abcdefghijklmnopqrstuvwxyz"
upper_case = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
special_characters = "!@#$%^&*()-+"
Input Format:
Output Format:
• Returns an integer. i.e., the minimum number of characters to add.
ample Input:
S
3
Ab1
Sample Output:
3
Explanation:
She can make the password strong by adding3 characters, for example, $hk, turning the
password into Ab1$hk which is strong.2 characters aren't enough since the length must
be at least 6.
Source Code:
password.c
ID: 247Y1A6790
scanf("%s", password);
int has_digit = 0, has_lower = 0, has_upper = 0, has_special = 0;
char special_characters[] = "!@#$%^&*()-+";
for (int i = 0; i < n; i++) {
if (isdigit(password[i])) {
has_digit = 1;
} else if (islower(password[i])) {
has_lower = 1;
} else if (isupper(password[i])) {
has_upper = 1;
2024-2028-CSD-B
} else {
for (int j = 0; special_characters[j] != '\0'; j++) {
if (password[i] == special_characters[j]) {
has_special = 1;
break;
}
}
User Output
3
Ab1
Test Case - 2
ID: 247Y1A6790
User Output
12
#CodeTantra#
1
Test Case - 3
User Output
2024-2028-CSD-B
12
aBcD1234!@#$
0
Test Case - 4
Aim:
A space explorer’s ship crashed on Mars! In a desperate attempt to call for help, the ship
sends a series of SOS messages to Earth. The original SOS message is a repeating pattern
ID: 247Y1A6790
of the string "SOS". However, cosmic radiation disrupts the signal, causing some
characters to change.
Given the signal received by Earth as a string, s, determine how many characters of the
SOS message have been altered during transmission.
Input Format:
• A single line containing a string s.
Constraints:
2024-2028-CSD-B
• 1 ≤ length of s ≤ 100
• length of s modulo 3 = 0
• s will contain only uppercase English letters, ascii[A-Z].
Output Format:
• Output a single integer, which is the number of letters that have been changed
during transmission.
ample Input:
S
SOSSPSSQSSOR
Sample Output:
3
Explanation:
Expected signal: SOSSOSSOSSOS
Recieved signal: SOSSPSSQSSOR
Difference: X X X
The length of the received signal is 12 characters.
Based on this length, the expected SOS message would be "SOSSOSSOSSOSS" (which is
"SOS" repeated 4 times).
Compare the received signal SOSSPSSQSSOR with the expected message
"SOSSOSSOSSOSS":
ID: 247Y1A6790
Source Code:
letters.c
#include <stdio.h>
#include <string.h>
int main() {
char received[1000];
int altered_count = 0;
scanf("%s", received);
int length = strlen(received);
2024-2028-CSD-B
for (int i = 0; i < length; i++) {
char expected_char = "SOS"[i % 3];
if (received[i] != expected_char) {
altered_count++;
}
}
printf("%d\n", altered_count);
User Output
SOSSOT
1
Test Case - 2
User Output
SOSSPSSQSSOR
3
0
0
SO
User Output
User Output
SOSSOSSOSSOS
Test Case - 4
Test Case - 3
Marri Laxman Reddy Institute of Technology and Management (Autonomous) 2024-2028-CSD-B ID: 247Y1A6790 Page No: 190
Date: 2024-12-
S.No: 82 Exp. Name: Happy string.
Aim:
Sarika has a string S with him. Sarika is happy if the string contains a contiguous
substring of length strictly greater than 2 in which all its characters are vowels.
ID: 247Y1A6790
Determine whether Sarika is happy or sad.
Input Format:
• One line of input: a single string,s .
Constraints:
• 3 ≤ |s| ≤ 1000, where |s| is the length of s.
• length of s modulo 3 = 0
• s will only contain lowercase English letters.
2024-2028-CSD-B
Output Format:
• Returns Happy if Sarika is happy, Otherwise, Sad.
Note: This question does not have partial weightages for test cases. All the test cases
must be passed.
string.c
#include <stdio.h>
ID: 247Y1A6790
int main() {
char str[1000]; // Assuming the maximum length of the string is 1000
characters
// Read the input string
scanf("%s", str);
int max_len = 0; // To store the maximum length of contiguous vowels
int current_len = 0; // To track the current length of a contiguous
vowel substring
// Iterate over the string to find the longest contiguous vowel
substring
2024-2028-CSD-B
for (int i = 0; i < strlen(str); i++) {
if (isVowel(str[i])) {
// If the character is a vowel, increase the current length
current_len++;
if (current_len > max_len) {
max_len = current_len;
}
Test Case - 2
ID: 247Y1A6790
User Output
aebcdefghij
Sad
Test Case - 3
User Output
abcdeeafg
2024-2028-CSD-B
Happy
Test Case - 4
User Output
Happy
Aim:
Given two strings needle and haystack, return the index of the first occurrence of needle in
haystack, or -1 if needle is not part of haystack.
ID: 247Y1A6790
Input Format:
• The first line should be a input string i.e.,haystack.
• The secondline should be a input string i.e.,needle
Constraints:
• 1 <= haystack.length, needle.length <= 104
• haystack and needle consist of only lowercase English characters.
Output Format:
• Return an integer representing the index.
2024-2028-CSD-B
Source Code:
index.c
#include <stdio.h>
#include <string.h>
int strStr(char *haystack, char *needle) {
return 0;
}
Execution Results - All test cases have succeeded!
User Output
sadbutsad
ID: 247Y1A6790
sad
0
Test Case - 2
User Output
short
longstrong
-1
2024-2028-CSD-B
Test Case - 3
User Output
abracadabra
ab
Test Case - 4
User Output
AbCdEfGh
cd
-1
Date: 2024-12-
S.No: 84 Exp. Name: Length of Last Word
Aim:
Given a string s consisting of words and spaces, return the length of the last word in the
string. A word is a maximalsubstringconsisting of non-space characters only.
ID: 247Y1A6790
Input Format:
• The first line should be a input string i.e.,s.
Constraints:
• 1 <= s.length <= 104
• s consists of only English letters and spaces ' '.
• There will be at least one word in s.
Output Format:
2024-2028-CSD-B
• Return an integer representing the length of last word.
Source Code:
length.c
ID: 247Y1A6790
while (i >= 0 && s[i] == ' ') {
i--;
}
// Count the length of the last word
while (i >= 0 && s[i] != ' ') {
length++;
i--;
}
return length;
}
2024-2028-CSD-B
int main() {
char str[10000]; // assuming the maximum length of string is 10000
// Read the input string
fgets(str, sizeof(str), stdin);
User Output
hello world
5
Test Case - 2
User Output
luffy is still joyboy
6
8
10
CodeTantra
User Output
User Output
C programming language
Test Case - 4
Test Case - 3
Marri Laxman Reddy Institute of Technology and Management (Autonomous) 2024-2028-CSD-B ID: 247Y1A6790 Page No: 198
Date: 2024-12-
S.No: 85 Exp. Name: Reverse Vowels of a String
Aim:
Given a string s, reverse only all the vowels in the string and return it. The vowels are
a, e, i, o and u, and they can appear in both lower and upper cases, more than once.
ID: 247Y1A6790
Input Format:
• The first line should be a input string i.e.,s.
Constraints:
• 1 <= s.length <= 3 * 105
• s consist of English alphabets contains both upper and lower case
Output Format:
• Return a reverse string.
2024-2028-CSD-B
Source Code:
reverse.c
ID: 247Y1A6790
if (c == vowels[i]) {
return 1; // It is a vowel
}
}
return 0; // It is not a vowel
}
void reverseVowels(char *s) {
int left = 0;
int right = strlen(s) - 1;
2024-2028-CSD-B
while (left < right) {
// Find the next vowel from the left
while (left < right && !isVowel(s[left])) {
left++;
}
return 0;
}
ID: 247Y1A6790
Execution Results - All test cases have succeeded!
Test Case - 1
User Output
hello
holle
2024-2028-CSD-B
Test Case - 2
User Output
CodeTantra
CadaTentro
User Output
CadaTentro
CodeTantra
Test Case - 4
User Output
ABCabc
aBCAbc
Test Case - 5
User Output
decision
Date: 2024-12-
S.No: 86 Exp. Name: Palindromic String
Aim:
You have been given a String s. You need to find and print whether this string is a
palindrome or not.
ID: 247Y1A6790
Input Format:
• The first line should contain the input string s.
Output Format:
• Return "YES" if the input string is a palindrome, "NO"Otherwise.
Source Code:
palindrome.c
2024-2028-CSD-B
Marri Laxman Reddy Institute of Technology and Management (Autonomous)
#include <stdio.h>
ID: 247Y1A6790
fgets(s, sizeof(s), stdin);
int left = 0;
int right = strlen(s) - 1;
2024-2028-CSD-B
if (s[left] != s[right]) {
printf("NO\n");
return 0; // Exit as soon as we find a mismatch
}
left++;
right--;
}
return 0;
}
User Output
madam
YES
Test Case - 2
User Output
NO
NO
YES
racecar
panama
palindrome
User Output
User Output
Test Case - 4
Test Case - 3
Marri Laxman Reddy Institute of Technology and Management (Autonomous) 2024-2028-CSD-B ID: 247Y1A6790 Page No: 204
Date: 2024-12-
S.No: 88 Exp. Name: Trimor Love
Aim:
Trimor loves codetantra. That's why he has a string s having length 10 made containing
only lowercase Latin letters. Trimor wants to know how many indices string s differs from
ID: 247Y1A6790
the string "codetantra".
For example string s="codemantra" differs from "codetantra" in 1indice(s), shown in bold.
Help Trimor by finding the number of indices where string s differs from "codetantra".
Input Format:
Single line of input contains a string s.
2024-2028-CSD-B
Output Format:
If the length of string s is not equal to 10, then print -1, otherwise print the number of
indices where string s differs.
Constraints:
Input string s must be of length 10 only
CharDiffer.c
#include <stdio.h>
ID: 247Y1A6790
// Target string
const char target[] = "codetantra";
2024-2028-CSD-B
for (int i = 0; i < 10; i++) {
if (s[i] != target[i]) {
count++;
}
}
// Print the result
printf("%d\n", count);
User Output
codemantra
1
Test Case - 2
User Output
coursecode
8
9
0
6
questionss
codetantra
codecourse
User Output
User Output
User Output
Test Case - 5
Test Case - 4
Test Case - 3
Marri Laxman Reddy Institute of Technology and Management (Autonomous) 2024-2028-CSD-B ID: 247Y1A6790 Page No: 207
Date: 2024-12-
S.No: 89 Exp. Name: Length of the Ladder
Aim:
A man needs to reach a window which is positioned above the ground at some height H
(in feet). There is some distance D (in feet) between the foot of the ladder and the wall.
ID: 247Y1A6790
The man wants to know how long the ladder should be to reach the window safely.
Write a C program to help the man know the length of the ladder.
Input Format:
• First line of input contains an integer H representing the height of the window.
• Second line of input contains an integer D representing the distance between the
foot of the ladder and the wall.
Output Format:
• The length of the ladder required, rounded to two decimal places.
2024-2028-CSD-B
Constraints:
• 1 <= H, D <= 104
Source Code:
LengthOfLadder.c
// Read the inputs: height of the window (H) and distance from the
wall (D)
scanf("%d", &H);
scanf("%d", &D);
return 0;
}
Execution Results - All test cases have succeeded!
User Output
40
ID: 247Y1A6790
9
41.00
Test Case - 2
User Output
15
10
18.03
2024-2028-CSD-B
Test Case - 3
User Output
10
10
Test Case - 4
User Output
15
5
15.81
Test Case - 5
User Output
10
15
18.03
Date: 2024-12-
S.No: 90 Exp. Name: Anagram Check
Aim:
Given two strings s and t, return true if t is an anagram of s, and false otherwise.
ID: 247Y1A6790
An Anagram is a word or phrase formed by rearranging the letters of a different word or
phrase, typically using all the original letters exactly once.
Input Format:
Single line of input contains two space separated strings representing s and t
Output Format:
Print True if the string t is an anagram of string s, otherwise print False.
Constraints:
2024-2028-CSD-B
1 <= s.length, t.length <= 5 * 104
s and t consists of lowercase English letters only
Source Code:
AnagramCheck.c
ID: 247Y1A6790
if (strlen(s) != strlen(t)) {
return 0; // False
}
2024-2028-CSD-B
freq[1][t[i] - 'a']++;
}
return 1; // True
}
int main() {
char s[50005], t[50005];
// Check if t is an anagram of s
if (areAnagrams(s, t)) {
printf("True\n");
} else {
printf("False\n");
}
return 0;
}
Execution Results - All test cases have succeeded!
User Output
anagram nagaram
ID: 247Y1A6790
True
Test Case - 2
User Output
rat car
False
Test Case - 3
2024-2028-CSD-B
User Output
carrace racecar
True
User Output
eat ate
True
Test Case - 5
User Output
eat bat
False
Exp. Name: First Unique Character in a Date: 2024-12-
S.No: 91
Aim:
Given a string s, find the first non-repeating character in it and return its index. If it does
not exist, return -1.
ID: 247Y1A6790
Input Format:
Single line of input contains a string s
Output Format:
Print the index of the first non-repeating character, if it does not exist, print -1
Constraints:
1 <= s.length <= 105
string s consists of only lowercase English letters
2024-2028-CSD-B
Source Code:
UniqueCharacterIndex.c
ID: 247Y1A6790
// Count the frequency of each character in the string
for (int i = 0; s[i] != '\0'; i++) {
freq[s[i] - 'a']++;
}
2024-2028-CSD-B
}
}
return 0;
}
Test Case - 2
ID: 247Y1A6790
User Output
abcdefghijklmnopqrstuvwxyza
1
Test Case - 3
User Output
codetantra
2024-2028-CSD-B
0
Test Case - 4
User Output
proper
Test Case - 5
User Output
abababacd
7
Date: 2024-12-
S.No: 92 Exp. Name: Return of the Robot
Aim:
A robot starts at the origin (0, 0) on a 2D plane. It is given a sequence of moves
represented by the string "moves". Each move is represented by 'R' (right), 'L' (left), 'U'
ID: 247Y1A6790
(up), or 'D' (down). The task is to determine if the robot returns to the origin after
completing all the moves. The robot's direction is irrelevant, and all moves have the same
magnitude. Return true if the robot ends up at the origin, and false otherwise.
Input Format:
Single line of input contains a string representing the moves of the robot
Output Format:
Print True if the robots returns to the origin after completing all the moves, otherwise
print False
2024-2028-CSD-B
Constraints:
1 <= moves.length <= 2 * 104
moves only contains the characters 'U', 'D', 'L' and 'R'
Source Code:
RobotReturns.c
ID: 247Y1A6790
if (moves[i] == 'R') {
x++; // Move right, increase x
} else if (moves[i] == 'L') {
x--; // Move left, decrease x
} else if (moves[i] == 'U') {
y++; // Move up, increase y
} else if (moves[i] == 'D') {
y--; // Move down, decrease y
}
}
2024-2028-CSD-B
// If the robot is back at the origin, return true
return x == 0 && y == 0;
}
int main() {
char moves[20001]; // Assuming the max length of moves is 2 * 10^4
// Read the input string representing the moves
scanf("%s", moves);
User Output
UD
True
Test Case - 2
User Output
Test Case - 3
ID: 247Y1A6790
User Output
URDL
True
Test Case - 4
User Output
UUDRL
2024-2028-CSD-B
False
Test Case - 5
User Output
UDUD
Aim:
Chandini is a bad student. Once his teacher asked her to print the reverse of a given
string. She took three hours to solve it. The teacher got agitated at Chandini and asked
ID: 247Y1A6790
you the same question. Can you solve it?
Input Format:
Single line of input contains a string
Output Format:
Print the reverse of the given string
Constraints:
1 <= string length <= 50
2024-2028-CSD-B
Source Code:
StringReverse.c
#include <stdio.h>
#include <string.h>
int main() {
return 0;
}
Execution Results - All test cases have succeeded!
User Output
chandini
ID: 247Y1A6790
inidnahc
Test Case - 2
User Output
reverse
esrever
Test Case - 3
2024-2028-CSD-B
User Output
string
gnirts
User Output
faculty
ytlucaf
Test Case - 5
User Output
solution
noitulos
Date: 2024-12-
S.No: 94 Exp. Name: Repeated String
Aim:
There is a string, S, of lowercase English letters that is repeated infinitely many times.
Given an integer, N, find and print the number of letter a's in the firstN letters of the
ID: 247Y1A6790
infinite string.
Input Format:
• First line of input contains the string S
• Second line of input contains the integer N
Output Format:
• Print the frequency of letter "a" in the substring
Constraints:
2024-2028-CSD-B
• 1 <= string length <= 100
• 1 <= n <= 1012
Example:
string = 'abaca'
n = 10
The substring we consider will be abacaabaca, the first 10 characters of the infinite string.
RepeatedString.c
#include <stdio.h>
ID: 247Y1A6790
scanf("%s", S);
scanf("%lld", &N);
2024-2028-CSD-B
count_a_in_S++;
}
}
return 0;
}
ID: 247Y1A6790
Test Case - 2
User Output
seedof
15
0
2024-2028-CSD-B
Test Case - 3
User Output
avacado
50
22
User Output
propose
50
0
Test Case - 5
User Output
parameter
90
20
Date: 2024-12-
S.No: 95 Exp. Name: Climbing Stairs
Aim:
You are climbing a staircase. It takes n steps to reach the top.
ID: 247Y1A6790
Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to
the top?
Constraints:
•1≤n ≤ 45
Input Format:
• The only line containsan integern.
Output Format:
2024-2028-CSD-B
• Return the integer which results in calculating the no.of distinct ways to climb a
staircase with n steps.
Source Code:
step.c
ID: 247Y1A6790
for (int i = 3; i <= n; i++) {
int current = first + second; // dp[i] = dp[i-1] + dp[i-2]
first = second; // move the second value to first
second = current; // move the current value to second
}
2024-2028-CSD-B
int n;
// Input the number of steps
scanf("%d", &n);
User Output
2
2
Test Case - 2
User Output
3
3
8
5
5
4
User Output
User Output
Test Case - 4
Test Case - 3
Marri Laxman Reddy Institute of Technology and Management (Autonomous) 2024-2028-CSD-B ID: 247Y1A6790 Page No: 226
Date: 2024-12-
S.No: 97 Exp. Name: Power of Four
Aim:
Given an integer n, return true if it is a power of four. Otherwise, return false.
An integer n is a power of four, if there exists an integer x such that n == 4
ID: 247Y1A6790
x
.
Constraints:
• −2 ≤ n ≤ 2 − 1
31 31
Input Format:
• The only line containsan integern
Output Format:
• Return true if n is a power of four. Otherwise, false.
Source Code:
2024-2028-CSD-B
power.c
#include <stdio.h>
#include <stdbool.h>
bool isPowerOfFour(int n) {
// A number is a power of 4 if:
User Output
16
ID: 247Y1A6790
true
Test Case - 2
User Output
5
false
Test Case - 3
2024-2028-CSD-B
User Output
1
true
User Output
0
false
Date: 2024-12-
S.No: 98 Exp. Name: Factorial using Recursion
Aim:
You are given an integer N . You need to print N ! - the factorial of N .
.
ID: 247Y1A6790
Constraints:
• 1 ≤ T ≤ 10
• 0 ≤ N ≤ 20
Input Format:
• The first line of the input contains a single integerT denoting the number of test
cases. The description ofT test cases follows.
• The first and only line of each test case contains a single integerN
Output Format:
2024-2028-CSD-B
• For each test case print a single line containing a single integerN !
Source Code:
factorial.c
#include <stdio.h>
// Function to compute the factorial of a number
}
int main() {
int t; // Number of test cases
scanf("%d", &t); // Read number of test cases
while (t--) {
int n; // The number for which we need to compute factorial
scanf("%d", &n); // Read the integer n
return 0;
}
Execution Results - All test cases have succeeded!
User Output
2
ID: 247Y1A6790
12
1
2
Test Case - 2
User Output
3
362
2024-2028-CSD-B
6
720
2
Test Case - 3
Test Case - 4
User Output
2
46
24
720
Date: 2024-12-
S.No: 99 Exp. Name: Fibonacci Number
Aim:
The Fibonacci numbers, commonly denoted F (n) form a sequence, called the Fibonacci
sequence, such that each number is the sum of the two preceding ones, starting from 0
ID: 247Y1A6790
and 1.That is,
F (0) = 0, F (1) = 1
Constraints:
•0≤n ≤ 30
2024-2028-CSD-B
Input Format:
• The first line of the input contains a single integern.
Output Format:
• Return a single integerafter calculating F (n).
Source Code:
ID: 247Y1A6790
unsigned long long result = 0;
// Calculate Fibonacci numbers iteratively
for (int i = 2; i <= n; i++) {
result = a + b;
a = b; // Update a to the previous Fibonacci number
b = result; // Update b to the current Fibonacci number
}
return result;
}
int main() {
2024-2028-CSD-B
int n;
scanf("%d", &n); // Read the input n
// Call the Fibonacci function and print the result
printf("%llu\n", fibonacci(n));
return 0;
}
User Output
3
2
Test Case - 2
User Output
4
3
Test Case - 3
5
5
55
10
User Output
Test Case - 4
Marri Laxman Reddy Institute of Technology and Management (Autonomous) 2024-2028-CSD-B ID: 247Y1A6790 Page No: 233
Date: 2024-12-
S.No: 100 Exp. Name: Best Divisor
Aim:
Kristen loves playing with and comparing numbers. She thinks that if she takes two
different positive numbers, the one whose digits sum to a larger number is better than
ID: 247Y1A6790
the other. If the sum of digits is equal for both numbers, then she thinks the smaller
number is better.
For example, Kristen thinks that 13 is better than 31 and that 12 is better than 11. Given
an integer n, can you find the divisor of n that Kristin will consider to be the best?
Constraints:
•0<n ≤ 10
5
Input Format:
2024-2028-CSD-B
• The first line of the input contains a single integern.
Output Format:
• Print an integer denoting the best divisor of n.
Source Code:
Divisor.c
ID: 247Y1A6790
}
return sum;
}
int main() {
int n;
scanf("%d", &n); // Read the input integer n
int best_divisor = -1; // To store the best divisor
int max_digit_sum = -1; // To track the maximum sum of digits
// Find all divisors of n
for (int i = 1; i * i <= n; i++) {
2024-2028-CSD-B
if (n % i == 0) { // i is a divisor
// Check the sum of digits of i
int sum_i = sum_of_digits(i);
if (sum_i > max_digit_sum || (sum_i == max_digit_sum && i <
best_divisor)) {
max_digit_sum = sum_i;
best_divisor = i;
28
13
28
13
12
User Output
User Output
User Output
User Output
Test Case - 4
Test Case - 3
Test Case - 2
Test Case - 1
Marri Laxman Reddy Institute of Technology and Management (Autonomous) 2024-2028-CSD-B ID: 247Y1A6790 Page No: 236
Date: 2024-12-
S.No: 101 Exp. Name: Perfect Number or Not
Aim:
A perfect number is a positive integer that is equal to the sum of its positive divisors,
excluding the number itself. A divisor of an integer x is an integer that can divide x
ID: 247Y1A6790
evenly.
Input Format:
A single line of input contains an integer n
Output Format:
Print True if n is a perfect number, otherwise return False.
2024-2028-CSD-B
Constraints:
1 <= n <= 108
Note: This question does not contains weghtage for test cases. All test cases must be
passed.
Source Code:
ID: 247Y1A6790
}
int sum = 1; // 1 is always a divisor
int sqrt_n = sqrt(n);
// Loop from 2 to sqrt(n) to find divisors
for (int i = 2; i <= sqrt_n; i++) {
if (n % i == 0) {
sum += i; // Add divisor i
if (i != n / i) { // Avoid adding the square root twice if n is a
perfect square
sum += n / i; // Add the complement divisor n / i
2024-2028-CSD-B
}
}
}
// Return true if sum of divisors equals n
return sum == n;
}
int main() {
User Output
28
True
Test Case - 2
ID: 247Y1A6790
Test Case - 3
User Output
6
True
Test Case - 4
2024-2028-CSD-B
User Output
45
False
Test Case - 5
Aim:
Given an integer num, repeatedly add all its digits until the result has only one digit, and
return it.
ID: 247Y1A6790
Input Format:
Single line of input contains an integer num
Output Format:
Print the result after adding all the digits till it becomes a single digit
Constraints:
0 <= num <= 231 - 1
Source Code:
2024-2028-CSD-B
AddDigits.c
#include <stdio.h>
int addDigits(int num) {
if (num == 0) {
return 0;
User Output
38
2
User Output
154
ID: 247Y1A6790
1
Test Case - 3
User Output
153
9
2024-2028-CSD-B
Test Case - 4
User Output
321456
3
User Output
132456
3
Date: 2024-12-
S.No: 103 Exp. Name: Something for Profit
Aim:
A friend of yours bought a used pressure cooker for an initial cost of X rupees. Later, she
sold it to another friend for Y rupees. However, she regretted the sale and decided to buy
ID: 247Y1A6790
it back by offering Z rupees. After having bought it again, she felt that she didn't really
need the cooker and sold it at an auction for W rupees. Can you determine whether she
made a profit or incurred a loss, and if so, how much?
Write a C program that takes the values of X, Y, Z, and W as input and calculates the
profit or loss.
Input Format:
• First line contains two space separated integers X, Y representing the initial cost
and the first sale price
• Second line contains two space separated integers Z, W representing the buy-back
2024-2028-CSD-B
cost and the auction sell price
Output Format:
• Print the amount if she got any profit (Positive numbers) or loss (negative
numbers) or if no gain of profit or loss, print 0 (zero)
Source Code:
#include <stdio.h>
int main() {
int X, Y, Z, W; // Declare variables to store the values of X, Y, Z,
and W
// Reading the input values
scanf("%d %d", &X, &Y); // First line: X and Y
scanf("%d %d", &Z, &W); // Second line: Z and W
// Calculate the total spent and total earned
int totalSpent = X + Z;
int totalEarned = Y + W;
// Calculate the net profit or loss
int profitOrLoss = totalEarned - totalSpent;
// Output the result based on the profit or loss
printf("%d\n", profitOrLoss);
return 0;
}
ID: 247Y1A6790
Test Case - 2
User Output
90 70
80 60
-40
2024-2028-CSD-B
Test Case - 3
User Output
40 50
60 50
0
User Output
150 200
250 250
50
Test Case - 5
User Output
80 50
60 50
-40
Date: 2024-12-
S.No: 104 Exp. Name: Reverse an Integer
Aim:
Given a signed 32-bit integer x, return x with its digits reversed. If reversing x causes the
value to go outside the signed 32-bit integer range [-231, 231 - 1], then return 0.
ID: 247Y1A6790
Input Format:
Single line of input contains an integer x
Output Format:
Print the reversed integer of x
Constraints:
-231 <= x <= 231 - 1
Source Code:
2024-2028-CSD-B
ReverseAnInteger.c
ID: 247Y1A6790
x /= 10;
// Check if reversing will cause overflow
if (reversed > INT_MAX / 10 || (reversed == INT_MAX / 10 &&
digit > 7)) {
return 0; // Overflow case
}
if (reversed < INT_MIN / 10 || (reversed == INT_MIN / 10 &&
digit < -8)) {
return 0; // Underflow case
}
2024-2028-CSD-B
reversed = reversed * 10 + digit;
}
return reversed;
}
int main() {
int x;
// Reading the input integer
User Output
1534236469
0
Test Case - 2
User Output
123
321
User Output
-5689
ID: 247Y1A6790
-9865
Test Case - 4
User Output
32154869
96845123
2024-2028-CSD-B
Test Case - 5
User Output
2147483649
0
Aim:
Given an integer array nums, move all 0's to the end of it while maintaining the relative
order of the non-zero elements.
ID: 247Y1A6790
Note that you must do this in-place without making a copy of the array.
Input Format:
• First line of input contains an integer N representing the size of array
• Second line contains N space separated integers representing the array elements
Output Format:
• Print the array after moving all the zero elements to the end
2024-2028-CSD-B
Constraints:
• 1 <= nums.length <= 104
• -231 <= nums[i] <= 231 - 1
Source Code:
MoveZeroesToEnd.c
ID: 247Y1A6790
// Swap the non-zero element with the element at position j
int temp = nums[i];
nums[i] = nums[j];
nums[j] = temp;
j++; // Increment the position for the next non-zero element
}
}
}
int main() {
int n;
2024-2028-CSD-B
// Read the size of the array
scanf("%d", &n);
int nums[n];
User Output
5
0 1 0 3 12
Test Case - 2
ID: 247Y1A6790
User Output
5
12030
1 2 3 0 0
Test Case - 3
User Output
2024-2028-CSD-B
1
0
0
Test Case - 4
Test Case - 5
User Output
6
000010
1 0 0 0 0 0
Date: 2024-12-
S.No: 106 Exp. Name: Number of 1 Bits
Aim:
Write a program that takes the binary representation of an unsigned integer and returns
the number of '1' bits it has (also known as the Hamming weight).
ID: 247Y1A6790
Input Format:
Single line of input contains the required binary string
Output Format:
Print the total no of '1' bits present in the given binary string
Constraints:
The input must be a binary string of length 32
Source Code:
2024-2028-CSD-B
NoOfOneBits.c
#include <stdio.h>
int main() {
char binary[33]; // Array to store the binary string, max length 32
plus null terminator.
Test Case - 2
ID: 247Y1A6790
User Output
00000000000000000000000010000000
1
Test Case - 3
User Output
11111111111111111111111111111101
2024-2028-CSD-B
31
Test Case - 4
User Output
00000011110000111000011001100110
Test Case - 5
User Output
00000000000000000000000000000000
0
Date: 2024-12-
S.No: 107 Exp. Name: Cut the Bread
Aim:
Martha is interviewing at Subway. One of the rounds of the interview requires her to cut a
bread of size L * Binto smaller identical pieces such that each piece is a square having
ID: 247Y1A6790
maximum possible side length with no left over piece of bread.
Input Format:
Single line of input contains two space separated integers L and B representing the
length and breadth of the bread
Output Format:
Print an integer that denotes the number of squares of maximum size, when the bread is
cut as per the given condition.
2024-2028-CSD-B
Constraints:
1 <= L, B <= 1000
Source Code:
CutTheBread.c
ID: 247Y1A6790
}
return a;
}
int main() {
int L, B;
2024-2028-CSD-B
int side_length = gcd(L, B);
User Output
22
1
Test Case - 2
User Output
69
6
2
1
40
44
50 80
12 24
User Output
User Output
User Output
Test Case - 5
Test Case - 4
Test Case - 3
Marri Laxman Reddy Institute of Technology and Management (Autonomous) 2024-2028-CSD-B ID: 247Y1A6790 Page No: 254
Date: 2024-12-
S.No: 108 Exp. Name: Points on a Line
Aim:
Given ntwo-dimensional points in space, determine whether they lie on some vertical or
horizontal line. If yes, print YES; otherwise, print NO.
ID: 247Y1A6790
Input Format:
• The first line contains a single positive integer, n, denoting the number of points.
• Next n lines containstwo space-separated integers detailing the respective values
ofandxi and yi (i.e., the coordinates of the ithpoint).
Output Format:
• Print YES if all the points lie on some vertical or horizontal line, otherwise print NO
Constraints:
2024-2028-CSD-B
2 <= n <= 10
-10 <= xi, yi <= 10
Source Code:
PointsOnALine.c
ID: 247Y1A6790
// Read the first point's coordinates
scanf("%d %d", &first_x, &first_y);
if (x != first_x) {
2024-2028-CSD-B
is_vertical = 0; // If x is not the same as the first x,it's not a
vertical line
}
if (y != first_y) {
is_horizontal = 0; // If y is not the same as the first y,it's not a
horizontal line
}
User Output
5
01
02
03
04
Test Case - 2
ID: 247Y1A6790
User Output
5
01
02
13
04
05
2024-2028-CSD-B
NO
Test Case - 3
User Output
5
Test Case - 4
User Output
5
10
20
31
40
50
NO
6
NO
59
48
37
26
15
10 10
User Output
Test Case - 5
Marri Laxman Reddy Institute of Technology and Management (Autonomous) 2024-2028-CSD-B ID: 247Y1A6790 Page No: 258
Exp. Name: Department-wise Salary
Date: 2025-01-
Aim:
ID: 247Y1A6790
You are building a payroll system for a company with multiple departments. Design a
program using structures that store employee details such as name, employee ID, and
salary. Implement an array of structures to store employee records for each department.
Calculate the total salary expenditure for each department and display it. Additionally,
identify the department with the highest salary expenditure and acknowledge it as the
top-performing department.
Structures:
Employee Structure:
• Name: A string to store the employee's name (up to 50 characters).
• Employee ID: An integer to store the unique ID of the employee.
2024-2028-CSD-B
• Salary: A floating-point number to store the employee's salary.
Department Structure:
• Name: A string to store the department's name (up to 50 characters).
• Employees: An array of Employee structures to store the details of each
employee in the department.
• Number of Employees: An integer to store the count of employees in the
Input Format:
1. The first line should contain an integer n, representing the number of departments.
2. For each department (repeat n times):
• Read the department name (a string).
• Read an integer m, which indicates the number of employees in that department.
• For each employee (repeat m times):
• (a) Read the employee name (a string).
• (b) Read the employee ID (an integer).
• (c) Read the employee salary (a floating-point number).
Output Format:
• For each department, print the department name followed by the total salary
expenditure, formatted to two decimal places.
• Finally, print the name of the top-performing department, which has the highest
total salary expenditure.
Source Code:
Salary.c
#include<stdio.h>
ID: 247Y1A6790
int emp_id;
float salary;
};
struct Department{
char name[MAX_NAME_LENGTH];
struct Employee employees[MAX_EMPLOYEES];
int num_employees;
};
float calculate_total_salary(struct Department dept){
float total_salary = 0.0;int i;
2024-2028-CSD-B
for ( i= 0; i < dept.num_employees; i++) {
total_salary += dept.employees[i].salary;
}
return total_salary;
}
int main(){
int num_departments,i,j;
ID: 247Y1A6790
Test Case - 1
User Output
2
Developer
2
Alice 1234 50000.00
Bob 5678 60000.00
2024-2028-CSD-B
Tester
3
Charlie 9876 55000.00
David 5432 75000.00
Eve 8765 40000.00
Developer: 110000.00
Test Case - 2
User Output
3
HR
1
John 1234 45000.00
Sales
2
Mary 5678 55000.00
Sam 9876 48000.00
Marketing
3
Emily 1357 60000.00
Michael 7890 70000.00
HR: 45000.00
ID: 247Y1A6790
Test Case - 3
User Output
2
Developer
1
Amelia 1233 89799.00
Tester
1
2024-2028-CSD-B
Andrin 7887 78000.00
Developer: 89799.00
Tester: 78000.00
Developer
User Output
1
Engineering
4
Alex 1234 60000.00
Ben 5678 55000.00
Carl 9876 70000.00
Diana 5432 65000.00
Engineering: 250000.00
Engineering
Date: 2025-01-
S.No: 111 Exp. Name: Student Details
Aim:
You have been assigned the task of developing a student grading system for a
prestigious college. Design a program using structures that store student details, such as
ID: 247Y1A6790
name, roll number, and marks in various subjects. Implement an array of structures to
store multiple student records and calculate the overall percentage for each student.
Additionally, provides a functionality to generate a grade for each student based on their
percentage and display it alongside their record.
Input Format:
• The first line contains an integer n, representing No. of students.
• The next line contains input from the user for Name, Roll number and Student
marks (Assume 5 subjects) in one line.
2024-2028-CSD-B
Output Format:
• Return structure with the given members.
Grading Criteria:
A: If the percentage is 90 or above.
B: If the percentage is 80 or above.
C: If the percentage is 70 or above.
Source Code:
student.c
//#include <stdio.h>#include <string.h>struct{};int main() {
ID: 247Y1A6790
int marks[5];
float percentage;
char grade;
};
void cal_per_and_grade(struct Student* student){
int total_marks=0;
for(int i=0;i<5;i++){
total_marks+=student->marks[i];
}
student->percentage=(float)total_marks/5;
2024-2028-CSD-B
if(student->percentage >=90){
student->grade= 'A';
}else if(student->percentage >=80){
student->grade= 'B';
}
else if(student->percentage >=60){
student->grade ='C';
ID: 247Y1A6790
Execution Results - All test cases have succeeded!
Test Case - 1
User Output
1
2024-2028-CSD-B
Steven
45
78 89 88 90 75
Name: Steven
Roll number: 45
Test Case - 2
User Output
3
John
101
98 90 92 88 91
Alice
102
85 78 90 92 80
Bob
103
75 80 68 88 70
Name: John
Roll number: 101
Percentage: 91.80
Grade: A
ID: 247Y1A6790
Roll number: 103
Percentage: 76.20
Grade: C
Test Case - 3
User Output
2
2024-2028-CSD-B
Emma
201
94 86 89 92 88
Sophia
202
78 82 86 90 76
Test Case - 4
User Output
1
Liam
301
88 90 94 92 85
Name: Liam
Roll number: 301
Grade: B
Marri Laxman Reddy Institute of Technology and Management (Autonomous) 2024-2028-CSD-B ID: 247Y1A6790 Page No: 267
Exp. Name: Average years of service of Date: 2025-01-
S.No: 112
Aim:
You are developing a soldier management system for an army unit. Each soldier's record
consists of the following information: name, rank, and years of service. Implement an
ID: 247Y1A6790
array of structures to store the records of multiple soldiers. Write a C program to
calculate and display the average years of service for all soldiers in the unit.
Input Format:
• The first line contains an integern, representing No. of soldiers.
• The next line contains input from the user for Name, Rank and years of service of
soldiers.
Output Format:
• Return average years of service of the soldiers.
Source Code:
2024-2028-CSD-B
soldier.c
ID: 247Y1A6790
float cal_avg_yrs(struct Soldier soldiers[],int n){
int total_years=0;
for(int i=0;i<n;i++){
total_years+=soldiers[i].years_of_service;
}
return (float) total_years / n;
}
int main(){
int n;
scanf("%d",&n);
2024-2028-CSD-B
struct Soldier soldiers[n];
for(int i=0;i<n;i++){
scanf("%s",soldiers[i].name);
scanf("%d",&soldiers[i].rank);
scanf("%d",&soldiers[i].years_of_service);
}
float avg_years=cal_avg_yrs(soldiers,n);
User Output
2
Henry
67
42
Jackson
34
43
Test Case - 2
ID: 247Y1A6790
42
Jackson
34
43
Liam
56
38
41.00
2024-2028-CSD-B
Test Case - 3
User Output
2
Emma
Test Case - 4
User Output
1
Amelia
50
35
35.00
Exp. Name: Ship Management System Date: 2025-01-
S.No: 113
Aim:
You are working on a ship management system for a naval fleet. Each ship's record
contains the following details: name, type (e.g., aircraft carrier, destroyer), and year of
ID: 247Y1A6790
commissioning. Implement an array of structures to store the ship records. Write a C
program to search for a specific type of ship within the fleet and display the names of all
ships belonging to that type.
Input Format:
• The first line contains an integern, representing No. of ships.
• The next line contains input from the user for the Name, type and year of
commissioning of n ships.
Output Format:
• The program should return the names of ships of the specified type. If no ships of
2024-2028-CSD-B
the specified type are found, it should display "No ships of type '[Type]' found in
the fleet." where '[Type]' is the type you're searching for.
Source Code:
ship.c
ID: 247Y1A6790
void search_ship_by_type(struct Ship ships[],int n,const char*
search_type){
int found=0;
for(int i=0;i<n;i++){
if(strcmp(ships[i].type,search_type)==0){
printf("Name of ship %d is %s\n",i+1,ships[i].name);
found=1;
}
}
if(!found){
2024-2028-CSD-B
printf("No ships of type '%s' found in the fleet\n",search_type);
}
}
int main(){
int n;
char search_type[50];
scanf("%d",&n);
User Output
2
Windsong Cruise 2013
ID: 247Y1A6790
Test Case - 2
User Output
3
Titanic AircraftCarrier 2000
QueenMary Battleship 2005
Olympic AircraftCarrier 2010
AircraftCarrier
2024-2028-CSD-B
Name of ship 1 is Titanic
Name of ship 3 is Olympic
Test Case - 3
User Output
Test Case - 4
User Output
2
Titanic Cruise 2000
QueenMary Cruise 2005
AircraftCarrier
Exp. Name: Find Pilot with Highest Date: 2025-01-
S.No: 114
Aim:
You have been assigned the task of developing a pilot roster system for an Air Force
squadron. Each pilot's record includes the following information: name, rank, and flight
ID: 247Y1A6790
hours. Implement an array of structures to store the pilot records. Write a C program to
find and display the pilot with the highest number of flight hours in the squadron.
Input Format:
• The first line contains an integern, representing No. of pilots.
• The next line contains input from the user for the Name, Rank and flight hours of n
pilots.
Output Format:
• Return the pilot with highest number of flight hours.
Source Code:
2024-2028-CSD-B
pilot.c
ID: 247Y1A6790
int main(){
int n;
scanf("%d",&n);
struct Pilot p[n];
for(int i=0;i<n;i++){
scanf("%s",p[i].name);
scanf("%s",p[i].rank);
scanf("%d",&p[i].fh);
}
int maxfh=p[0].fh;
2024-2028-CSD-B
int index=0;
for(int i=1;i<n;i++){
if(p[i].fh>maxfh){
maxfh=p[i].fh;
index=i;
}
}
User Output
3
John 5 120
Alice 7 150
Bob 4 180
Bob
Test Case - 2
User Output
ID: 247Y1A6790
James
Test Case - 3
User Output
2
Olivia 4 100
Liam 6 300
2024-2028-CSD-B
Liam
Test Case - 4
User Output
2
Aim:
You have been assigned the task of creating a customer billing system using an array of
structures. Each structure should store the customer's name, account number, and total
ID: 247Y1A6790
amount due. Implement functions to add customer records, display all records, and find
the customer with the highest amount due.
Input Format:
• First line of input contains an integer K denoting the no of customers
• Next lines contains details of the K customers: Name (N), Account number (A),
Amount Due (D) in each line
Output Format:
• Firstly, display all the customers name, account number, and amount due.
2024-2028-CSD-B
• Finally, print the customer name with highest due.
Constraints
• N consists of English letters only
• 1 <= N <= 50
• 5 <= length.AccountNumber <= 12
Source Code:
ID: 247Y1A6790
void addCustomerRecords(struct Customer customers[],int k){
for(int i=0;i<k;i++){
getchar();
fgets(customers[i].name,sizeof(customers[i].name),stdin);
customers[i].name[strcspn(customers[i].name,"\n")]='\0';
fgets(customers[i].account_number,sizeof(customers[i].account_number),stdin);
customers[i].account_number[strcspn(customers[i].account_number,"\n")]='\0';
scanf("%f",&customers[i].amount_due);
}
}
2024-2028-CSD-B
void displayCustomerRecords(struct Customer customers[],int k){
for(int i=0;i<k;i++){
printf("%s ",customers[i].name);
printf("%s ",customers[i].account_number);
printf("%.2f\n",customers[i].amount_due);
}
}
User Output
3
ID: 247Y1A6790
A
13245
330
B
98765
213
C
675476
778
2024-2028-CSD-B
A 13245 330.00
B 98765 213.00
C 675476 778.00
C 778.00
Test Case - 2
Test Case - 3
User Output
1
1548796
745.5
Test Case - 4
ID: 247Y1A6790
User Output
2
Alpha
124563
986.5
Beta
357842
2024-2028-CSD-B
954.6
Alpha 124563 986.50
Beta 357842 954.60
Alpha 986.50
Test Case - 5
Aim:
You are working on a car inventory management system using an array of structures. Each
structure should hold the details of a car, including the make, model, and year of
ID: 247Y1A6790
manufacture. Implement functions to add car records, display all records, and find the
newest car in the inventory.
Input Format:
First line of input contains an integer X denoting the no of cars in inventory.
Next lines contains details of X cars: car maker name (N) of character datatype, model
name (M) of character datatype, year (yyyy) of integer type in each line.
Output Format:
Firstly, display all the records and then the details of the newest car.
2024-2028-CSD-B
Constraints:
1 <= N <= 50
1 <= M <= 50
Source Code:
CarInventory.c
ID: 247Y1A6790
void add(struct Car cars[],int x){
for(int i=0;i<x;i++){
getchar();
fgets(cars[i].make,sizeof(cars[i].make),stdin);
cars[i].make[strcspn(cars[i].make,"\n")]='\0';
fgets(cars[i].model,sizeof(cars[i].model),stdin);
cars[i].model[strcspn(cars[i].model,"\n")]='\0';
scanf("%d",&cars[i].year);
}
}
2024-2028-CSD-B
void display(struct Car cars[],int x){
for(int i=0;i<x;i++){
printf("%s\n",cars[i].make);
printf("%s\n",cars[i].model);
printf("%d\n",cars[i].year);
}
}
User Output
3
ID: 247Y1A6790
Mervedes-Benz
A-Class
2022
Nissan
Altima
2023
Ford
Escape
2020
2024-2028-CSD-B
Mervedes-Benz
A-Class
2022
Nissan
Altima
2023
Test Case - 2
User Output
2
Ford
Altima
2021
Nissan
Escape
2022
Ford
Altima
2021
Escape
2022
Test Case - 3
ID: 247Y1A6790
User Output
3
Australia
FordFalcon
1960
Argentina
ToyotaHiLux
1960
Brazil
2024-2028-CSD-B
Volkswagen
1980
Australia
FordFalcon
1960
Argentina
Test Case - 4
User Output
2
China
WulingHongguang
2010
France
RenaultClio
1990
WulingHongguang
2010
ID: 247Y1A6790
Test Case - 5
User Output
1
CzechRepublic
SkodaOctivia
1996
CzechRepublic
2024-2028-CSD-B
SkodaOctivia
1996
CzechRepublic SkodaOctivia 1996
Aim:
You are developing a product inventory management system for a retail store. Each
product has a unique identifier, name, price, and quantity in stock. Implement an array of
ID: 247Y1A6790
structures to store the product records. Create functions to add new products, update
product details, display all products, and search for products based on their identifier or
name.
Input Format:
Enter your choice 'C' as an integer value
Enter product identifier 'I' in string
Enter product name 'N' as string
Enter product price 'P' as integer
Enter product quantity 'Q' as integer
2024-2028-CSD-B
Note:
If C == 1, it means to insert a product
If C == 2, it means to print the count of no of products and the details of the products
If C == 3, it means to search for a product
If C == 4, it means to means to exit from the program
Constraints:
1 <= C <= 4
1 <= I.length <= 50
1 <= N.length <= 50
1 <= P <= 100
1 <= Q <= 100
Source Code:
ProductInventory.c
#include<stdio.h>
ID: 247Y1A6790
int quantity;
};
void add(struct Pro pros[],int *count){
if(*count >=max){
return;
}
getchar();
fgets(pros[*count].iden,sizeof(pros[*count].iden),stdin);
pros[*count].iden[strcspn(pros[*count].iden,"\n")]='\0';
fgets(pros[*count].name,sizeof(pros[*count].name),stdin);
2024-2028-CSD-B
pros[*count].name[strcspn(pros[*count].name,"\n")]='\0';
scanf("%d",&pros[*count].price);
scanf("%d",&pros[*count].quantity);
(*count)++;
}
void display(struct Pro pros[],int count){
if(count==0){
ID: 247Y1A6790
}
}
int main(){
struct Pro pros[max];
int proc=0;
int choice;
while(1){
scanf("%d",&choice);
if(choice==1){
add(pros,&proc);
2024-2028-CSD-B
}
else if(choice==2){
display(pros,proc);
if(proc==0)
printf("%d\n",proc);
}
else if(choice==3){
User Output
3
apple
Product Not Found
Test Case - 2
ID: 247Y1A6790
User Output
1
PAPL
PineApple
15
20
2
1
2024-2028-CSD-B
PAPL PineApple 15 20
4
Test Case - 3
User Output
Test Case - 4
User Output
2
0
ID: 247Y1A6790
10
2
1
Bnn Banana 48 10
1
APL
apple
50
25
2024-2028-CSD-B
1
DGN
DragonFruit
10
120
Test Case - 5
1
Ferrero
ID: 247Y1A6790
truffle
haz
12
1
1
disko
choco
290
2024-2028-CSD-B
12
2
3
Ferrero milk 100 2
truffle haz 12 1
disko choco 290 12
Aim:
You are tasked with managing bank accounts for two clients: one with the State Bank of
India (SBI) and another with the ICICI Bank. You need to implement a system where the
ID: 247Y1A6790
bank account details can be inquired, and money can be withdrawn based on user input.
Create a class Account with attributes: name, id, and balance. Implement methods
to: Inquire about the balance. Withdraw money if sufficient balance is available.
Input Format:
• Enter the name, ID, and initial balance for the SBI account.
• Enter the name, ID, and initial balance for the ICICI account.
• For each account, specify the amount to withdraw.
Output Format:
2024-2028-CSD-B
• Display the details of each account.
• Show the results of the withdrawal operations including success or failure
messages.
Note: Refer to the visible test cases for the input and output layout of the program
Source Code:
ID: 247Y1A6790
string id;
float balance;
Account (string acc_name,string acc_id,float acc_balance)
{
name=acc_name;
id=acc_id;
balance=acc_balance;
}
void inquire_balance()
{
2024-2028-CSD-B
cout<<name<<endl;
cout<<id<<endl;
cout<<balance<<endl;
}
void withdraw(float amount)
{
if (amount<=balance){
ID: 247Y1A6790
icic_account.withdraw(withdraw_amount);
return 0;
}
2024-2028-CSD-B
User Output
ram
123
6790
yash
Test Case - 2
alia
678
ID: 247Y1A6790
SBI Account Details:
alia
678
90000
500
Amount withdrawn: 500
New Balance: 89500
ICICI Account Details:
harish
2024-2028-CSD-B
6765
90500
1000
Amount withdrawn: 1000
New Balance: 89500
Aim:
You are tasked with implementing a banking application that handles three types of
accounts: SavingsAccount, CheckingAccount, and LoanAccount. Each account
ID: 247Y1A6790
type has specific behaviors for depositing, withdrawing, and maintaining a balance.
• SavingsAccount: Starts with an initial balance of $1000.
• CheckingAccount: Starts with an initial balance of $2000.
• LoanAccount: Starts with an amount owed of $50,000. Deposits reduce the owed
amount, while withdrawals increase it.
The application uses an abstract base class called Account. This class defines common
methods such as deposit(), withdraw(), and getBalance(), which must be
implemented by all derived classes. This allows users to interact with different account
2024-2028-CSD-B
types through a common interface without needing to understand the specific details of
each account type.
Requirements:
Abstract Base Class: Account
Methods:
• deposit(double amount)
Derived Classes(Subclasses)
A. Class SavingsAccount
• Attributes: balance
• A constructor which initializes the balance to 1000
• Override deposit(double amount) to add the amount to the balance
• Override withdraw(double amount) to reduce the given amount from
balance if the amount is less than the balance.
• Override getBalance() to return the balance amount
B. Class CheckingAccount
• Attributes: balance
• A constructor which initializes the balance to 2000
• Override deposit(double amount) to add the amount to the balance
• Override withdraw(double amount) to reduce the given amount from balance
if the amount is less than the balance.
• Override getBalance() to return the balance amount
C. Class LoanAccount
• Attributes: balance
ID: 247Y1A6790
The program should allow users to perform the following operations:
14. Choose an account type.
15. Deposit a specified amount.
16. Withdraw a specified amount.
17. Display the current balance.
Input Format:
The user first selects the type of account:
2024-2028-CSD-B
• 1 for SavingsAccount
• 2 for CheckingAccount
• 3 for LoanAccount
After selecting an account type, the user enters an amount to deposit.
The user then enters an amount to withdraw.
Output Format:
bankApplication.cpp
#include <iostream>
ID: 247Y1A6790
virtual double getBalance() const=0;
virtual ~Account() {}
};
class SavingsAccount : public Account {
public:
double balance;
public:
SavingsAccount() : balance(1000) {}
void deposit(double amount) override {
balance+=amount;
2024-2028-CSD-B
}
void withdraw(double amount)override{
if(amount <= balance){
balance-=amount;
}
else{
cout << "Insufficient funds"<< endl;
ID: 247Y1A6790
public:
double balance;
public:
LoanAccount(): balance(50000) {}
void deposit(double amount) override{
balance-=amount;
}
void withdraw(double amount) override{
balance+=amount;
}
2024-2028-CSD-B
double getBalance() const override{
return balance;
}
};
int main() {
int choice;
double amount;
switch (choice) {
case 1:
std::cin >> amount;
accounts[0]->deposit(amount);
std::cin >> amount;
accounts[0]->withdraw(amount);
std::cout << accounts[0]->getBalance() << "\n";
break;
case 2:
ID: 247Y1A6790
case 3:
std::cin >> amount;
accounts[2]->deposit(amount);
std::cin >> amount;
accounts[2]->withdraw(amount);
std::cout << accounts[2]->getBalance() << "\n";
break;
default:
std::cout << "Invalid choice\n";
break;
2024-2028-CSD-B
}
// Clean up
for (int i = 0; i < 3; ++i) {
delete accounts[i];
}
User Output
Choose an account type to operate on:
1. Savings Account
2. Checking Account
3. Loan Account
1
2000
4000
Insufficient funds
3000
Test Case - 2
ID: 247Y1A6790
3. Loan Account
2
1000
500
2500
Test Case - 3
User Output
2024-2028-CSD-B
Choose an account type to operate on:
1. Savings Account
2. Checking Account
3. Loan Account
3
4000
Aim:
You are developing a graphical user interface (GUI) library that includes various types of
buttons. The base class is Button, and you will create subclasses such as ImageButton,
ID: 247Y1A6790
ToggleButton, and RadioButton.
Requirements:
Base Class: Button
Properties:
• label: A string representing the button's label.
• size: An integer representing the button's size.
Methods:
• click(): A method that simulates clicking the button.
2024-2028-CSD-B
Derived Subclasses:
A. Class ImageButton:
• An attribute imagePath (std::string): This private member variable holds
the file path of the image associated with the button
• A Constructor ImageButton(const std::string& lbl, int sz, const
B. Class ToggleButton:
• An attribute isOn (bool): This private member variable holds the current state
of the toggle button. It indicates whether the button is in the "ON" state (true) or
"OFF" state (false).
• A Constructor ToggleButton(const std::string& lbl, int sz, int
state): which takes three parameters: lbl: A string for the button's label
(inherited from the base class), sz: An integer representing the size of the button
(also inherited), state: An integer that specifies the initial state of the toggle
button, which is used to set the isOn attribute.
• click(): This method overrides a virtual function from the base class Button. It
provides a specific implementation for the ToggleButton class, which outputs a
message indicating the current state of the button after it has been toggled.
• An attribute group (std::string): This private member variable holds the
name of the group to which the radio button belongs.
ID: 247Y1A6790
• click(): This method overrides a virtual function from the base class Button.
It provides a specific implementation for the RadioButton class, which outputs a
message indicating that the button has been selected.
Input Format:
The program will prompt the user to select a button type and then provide the necessary
details based on the selected button type.
Choose Button Type:
• 1 for Image Button
• 2 for Toggle Button
2024-2028-CSD-B
• 3 for Radio Button
Input Details:
For Image Button:
• Label (string): The label of the button.
• Size (integer): The size of the button.
• Image Path (string): The path to the image.
For Toggle Button:
Output Format:
The output will depend on the type of button selected:
• ImageButton: Message format: ImageButton [label] clicked with image:
[imagePath]
• ToggleButton: Message format: ToggleButton [label] toggled [ON/OFF]
• RadioButton: Message format: RadioButton [label] selected in group: [group]
Source Code:
guiLibrary.cpp
#include <iostream>
ID: 247Y1A6790
int size;
public:
Button(const string& lbl,int sz) : label(lbl),size(sz) {}
virtual void click()=0;
virtual ~Button() {}
};
// Subclass: ImageButton
class ImageButton : public Button {
private:
string imagePath;
2024-2028-CSD-B
public:
ImageButton(const string& lbl,int sz,const string& imgPath)
: Button(lbl,sz),imagePath(imgPath) {}
void click() override{
cout << "ImageButton " <<label << " clicked with image: "
<<imagePath << endl;
}
ID: 247Y1A6790
int main() {
int buttonType;
std::cout << "Choose button type:\n";
std::cout << "1. Image Button\n";
std::cout << "2. Toggle Button\n";
std::cout << "3. Radio Button\n";
std::cin >> buttonType;
std::string label;
int size,state;
2024-2028-CSD-B
Button* button = nullptr;
switch (buttonType) {
case 1: { // Image Button
std::string imagePath;
std::cin >> label;
std::cin >> size;
// Clean up
delete button;
ID: 247Y1A6790
return 0;
}
2024-2028-CSD-B
User Output
Choose button type:
1. Image Button
2. Toggle Button
3. Radio Button
1
Test Case - 2
User Output
Choose button type:
1. Image Button
2. Toggle Button
3. Radio Button
2
Tog1
200
1
ToggleButton Tog1 toggled ON
Test Case - 3
ID: 247Y1A6790
3. Radio Button
3
radio1
200
language
RadioButton radio1 selected in group: language
2024-2028-CSD-B
Marri Laxman Reddy Institute of Technology and Management (Autonomous)
Exp. Name: E-Commerce Platform with Date: 2025-01-
S.No: 124
Aim:
You are tasked with creating a simple e-commerce system using object-oriented
programming in C++. You will implement a base class Product and three derived
ID: 247Y1A6790
classes: Electronics, Clothing, and Books according to the following
requirements.
Requirements:
Base Class: Product
Attributes:
• name (string): The name of the product.
• price (double): The price of the product.
Methods:
2024-2028-CSD-B
• A constructor to initialize name and price.
• applyDiscount(double percentage): Reduces the product price by the
given percentage.
• display(): Displays the product's name and price.
B. Class Clothing:
• Additional attributes:
• size (string): The size of the clothing (e.g., "M", "L", "XL").
• color (string): The color of the clothing (e.g., "Red", "Blue").
• Override display() to show the product's name, price, size, and color.
C. Class Books:
• Additional attribute: author (string): The author of the book.
• Override display() to show the product's name, price, and author.
Input Format:
1.The program will first prompt the user to choose the product type:
• 1 for Electronics
ID: 247Y1A6790
• Clothing: Name (string), Price (double), Size (string), Color (string)
• Books: Name (string), Price (double), Author (string)
3.The user will then input the discount percentage (double), which will be applied to the
product price.
Output Format:
The output messages will be displayed in the following format based on the selected
product type:
Electronics:
Product Name: [Product Name]
Price: $[Original Price]
2024-2028-CSD-B
Warranty Period: [Warranty Period] months
Final Price after Discount: $[Final Price]
Clothing:
Product Name: [Product Name]
Price: $[Original Price]
Size: [Size]
Color: [Color]
Final Price after Discount: $[Final Price]
eCommerce.cpp
#include <iostream>
ID: 247Y1A6790
double price;
public:
Product(const string& n,double p) : name(n), price(p) {}
void applyDiscount(double percentage) {
price-=price * (percentage /100);
}
virtual void display() const=0;
virtual ~Product() {}
};
// Subclass: Electronics
2024-2028-CSD-B
class Electronics : public Product{
private:
int warrantyPeriod;
public:
Electronics(const string& n,double p,int w) :
Product(n,p),warrantyPeriod(w) {}
void display() const override{
ID: 247Y1A6790
cout << "Product Name: " << name <<endl;
cout << "Price: " <<price <<endl;
cout << "Author: " << author << endl;
}
};
int main() {
int productType;
2024-2028-CSD-B
std::cout << "Choose product type:\n";
std::cout << "1. Electronics\n";
std::cout << "2. Clothing\n";
std::cout << "3. Books\n";
std::cin >> productType;
std::string name;
switch (productType) {
case 1: { // Electronics
int warranty;
//std::cout << "Enter product name: ";
std::cin >> name;
//std::cout << "Enter price: ";
std::cin >> price;
//std::cout << "Enter warranty period (months): ";
std::cin >> warranty;
product = new Electronics(name, price, warranty);
break;
}
case 2: { // Clothing
std::string size, color;
//std::cout << "Enter product name: ";
std::cin >> name;
//std::cout << "Enter price: ";
std::cin >> price;
//std::cout << "Enter size: ";
std::cin >> size;
ID: 247Y1A6790
std::string author;
//std::cout << "Enter product name: ";
std::cin >> name;
//std::cout << "Enter price: ";
std::cin >> price;
//std::cout << "Enter author: ";
std::cin >> author;
product = new Books(name, price, author);
break;
}
2024-2028-CSD-B
default:
std::cout << "Invalid choice\n";
return 1;
}
return 0;
}
User Output
Choose product type:
1. Electronics
2. Clothing
3. Books
1
2000
5
ID: 247Y1A6790
Test Case - 2
User Output
Choose product type:
1. Electronics
2. Clothing
3. Books
2
2024-2028-CSD-B
Shirt
2100
M
Blue
25
Product Name: Shirt
Test Case - 3
User Output
Choose product type:
1. Electronics
2. Clothing
3. Books
3
Book1
500
Ravi
10
Product Name: Book1
Price: 450
Exp. Name: Building Educational Date: 2025-01-
S.No: 125
Aim:
Your task is to create educational software that manages various types of learning
resources. You need to establish a base class called LearningResource that includes
ID: 247Y1A6790
common properties like title and subject, along with a method named display()
for showing resource details.
2024-2028-CSD-B
subject of the book (also inherited), a: A string that specifies the author of the
book.
• display() : This method overrides a virtual function from the base class
LearningResource.
B. Class VideoLecture:
• Attributes duration (int), videoURL (std::string)
C. Class Quiz:
• An attribute questions (std::vector<std::string>)
• A Constructor Quiz(const std::string& t, const std::string& s,
const std::vectorstd::string& qs): where t: A string for the title of the
quiz (inherited from the base class LearningResource), s: A string for the
subject of the quiz (also inherited), qs: A vector of strings that contains the
questions for the quiz.
• display() : This method overrides a virtual function from the base class
LearningResource.
Input Format
When the program runs, the user will be prompted to choose a type of learning resource
to create. Depending on the choice, the following inputs will be required:
ID: 247Y1A6790
• Title: [Enter the title of the video lecture]
• Subject: [Enter the subject]
• Duration: [Enter the duration in minutes]
• Video URL: [Enter the URL for the video]
For Quiz:
• Title: [Enter the title of the quiz]
• Subject: [Enter the subject]
• Number of Questions: [Enter the number of questions]
• Questions: [Enter each question]
Output Format
2024-2028-CSD-B
Based on the type of learning resource created, the output will be displayed in the
following format:
For Book:
Title: [Title]
Subject: [Subject]
Author: [Author]
For VideoLecture:
educationalApp.cpp
#include <iostream>
ID: 247Y1A6790
string subject;
public:
LearningResource(const string& t,const string& s) : title(t),
subject(s) {}
virtual void display() const=0;
virtual ~LearningResource() {}
};
class Book : public LearningResource{
private:
string author;
2024-2028-CSD-B
public:
Book(const string& t,const string& s,const string& a)
: LearningResource(t,s),author(a) {}
void display() const override{
cout << "Title: " << title << endl;
cout << "Subject: " << subject << endl;
cout << "Author: " <<author << endl;
ID: 247Y1A6790
}
};
int main() {
int resourceType;
std::cout << "Choose resource type:\n";
std::cout << "1. Book\n";
std::cout << "2. Video Lecture\n";
std::cout << "3. Quiz\n";
2024-2028-CSD-B
std::cin >> resourceType;
switch (resourceType) {
std::cin.ignore();
std::getline(std::cin, title);
std::getline(std::cin, subject);
std::cin >> duration;
std::cin.ignore();
std::getline(std::cin, videoURL);
if (duration <= 0) {
std::cout << "Duration must be greater than zero\n";
ID: 247Y1A6790
}
case 3: { // Quiz
std::cin.ignore();
std::getline(std::cin, title);
std::getline(std::cin, subject);
std::cin >> numQuestions;
if (numQuestions <= 0) {
std::cout << "Quiz must have at least one question\n";
return 1;
2024-2028-CSD-B
}
std::cin.ignore();
for (int i = 0; i < numQuestions; ++i) {
std::string question;
std::cout << "Enter question " << (i + 1) << ":\n";
std::getline(std::cin, question);
questions.push_back(question);
return 0;
}
User Output
Choose resource type:
1. Book
2. Video Lecture
ID: 247Y1A6790
Bjarne Stroutrup
Title: C++ Programming
Subject: Computer Science
Author: Bjarne Stroutrup
Test Case - 2
User Output
Choose resource type:
2024-2028-CSD-B
1. Book
2. Video Lecture
3. Quiz
2
Advanced Machine Learning
Artificial Intelligence
Test Case - 3
User Output
Choose resource type:
1. Book
2. Video Lecture
3. Quiz
3
Programming Quiz
Computer Science
2
What is a pointer
Enter question 2:
ID: 247Y1A6790
What is a pointer
What is polymorphism
2024-2028-CSD-B
Marri Laxman Reddy Institute of Technology and Management (Autonomous)
Exp. Name: Design a System to Classify
Date: 2025-01-
Aim:
ID: 247Y1A6790
Problem Statement:
You need to design a system to classify and manage information about various types of
animals. The system should be able to handle common characteristics of animals (such as
name and habitat) as well as specific characteristics based on the type of animal (such as
mammals, birds, and reptiles). The system should support the following actions:
Requirements:
2024-2028-CSD-B
• habitat: Where the animal lives (e.g., forest, desert, ocean).
Methods:
• A constructor Animal(const std::string& n, const std::string& h):
This constructor initializes an Animal object. It takes two parameters: n: A string
for the name of the animal, h: A string for the habitat of the animal.
• eat(): Prints the message "The animal is eating"
Derived Classes:
ID: 247Y1A6790
• displayInfo() : This overridden method does the following: Calls the base class
method Animal::displayInfo() to display the name and habitat of the bird.
2024-2028-CSD-B
• displayInfo() : This overridden method does the following: Calls the base class
method Animal::displayInfo() to display the name and habitat of the
reptile.
Task:
18. Implement the class structure using inheritance.
Input Format:
• The user will first choose the type of animal they wish to create: Mammal, Bird, or
Reptile.
• The user will then input the common attributes of the animal (name, habitat).
• Depending on the type of animal, additional attributes specific to the type will be
requested (e.g., for Mammals, hasFur will be requested).
• Finally, the user can invoke actions (eat(), sleep(), fly(), etc.) based on the animal
type.
Output Format:
• After creating the animal, the system should display the information about the
animal.
• When invoking actions like eat(), sleep(), and specific actions (e.g., fly(), nurse(),
crawl()), appropriate messages should be printed.
Note: Refer to the visible test cases for detailed input and output layout.
Source Code:
animalInheritance.cpp
Marri Laxman Reddy Institute of Technology and Management (Autonomous) 2024-2028-CSD-B ID: 247Y1A6790 Page No: 323
#include <iostream>
ID: 247Y1A6790
string habitat;
public:
Animal(const string& n,const string& h) : name(n),habitat(h) {}
void eat(){
cout << "The animal is eating" << endl;
}
void sleep(){
cout << "The animal is sleeping" <<endl;
}
virtual void displayInfo() const{
2024-2028-CSD-B
cout << "Name: " << name << endl;
cout << "Habitat: " << habitat << endl;
}
virtual ~Animal() {}
};
// Derived class Mammal
class Mammal :public Animal{
ID: 247Y1A6790
cout << "The retile is crawing" << endl;
}
void displayInfo() const override{
Animal:: displayInfo();
}
};
int main() {
int choice;
2024-2028-CSD-B
cout << "Choose an animal type:\n1. Mammal\n2. Bird\n3. Reptile\n";
cin >> choice;
switch(choice) {
ID: 247Y1A6790
}
case 3: { // Reptile
getline(cin, name);
getline(cin, habitat);
Reptile reptile(name, habitat);
reptile.displayInfo();
cout << "Actions:\n1. Eat\n2. Sleep\n3. Crawl\nChoose an
action: ";
int action;
cin >> action;
2024-2028-CSD-B
if (action == 1) reptile.eat();
else if (action == 2) reptile.sleep();
else if (action == 3) reptile.crawl();
break;
}
default:
cout << "Invalid option" << endl;
return 0;
}
User Output
Choose an animal type:
1. Mammal
2. Bird
3. Reptile
1
Lion
Forest
1
Name: Lion
Habitat: Forest
ID: 247Y1A6790
Choose an action:
1
The animal is eating
Test Case - 2
User Output
Choose an animal type:
2024-2028-CSD-B
1. Mammal
2. Bird
3. Reptile
2
Eagle
Mountain
Test Case - 3
User Output
Choose an animal type:
1. Mammal
2. Bird
3. Reptile
3
Snake
2
Desert
1. Eat
3. Crawl
2. Sleep
Actions:
Name: Snake
Habitat: Desert
Choose an action:
Marri Laxman Reddy Institute of Technology and Management (Autonomous) 2024-2028-CSD-B ID: 247Y1A6790 Page No: 328
Exp. Name: Drawing Various Shapes Date: 2025-01-
S.No: 127
Aim:
You are required to implement an application that can draw various shapes such as Circle,
Rectangle, and Triangle using polymorphism. You will create an abstract base class Shape
ID: 247Y1A6790
with a method draw(). Then, you will implement three subclasses: Circle, Rectangle,
and Triangle. Each subclass should provide its specific implementation of the draw
method. The application should then be able to handle any shape object through the
Shape interface.
The application should accept input from the user to choose a shape and then output the
drawing command corresponding to that shape.
Class Design:
Abstract Base Class Shape:
2024-2028-CSD-B
The class will define a pure virtual method draw() which will be overridden by the
subclasses.
Polymorphism:
Your application should use a reference to the base class (Shape) to invoke the
appropriate draw() method for the specific shape object, demonstrating polymorphism.
Input Format:
The program will prompt the user to choose a shape from the following options:
• 1 for Circle
• 2 for Rectangle
• 3 for Triangle
Based on the user's choice, the program will draw the corresponding shape.
Output Format:
For each shape, the program will output a message indicating which shape is being
drawn:
• For Circle: "Drawing a Circle"
• For Rectangle: "Drawing a Rectangle"
• For Triangle: "Drawing a Triangle"
Source Code:
drawingShapes.cpp
Marri Laxman Reddy Institute of Technology and Management (Autonomous) 2024-2028-CSD-B ID: 247Y1A6790 Page No: 330
#include <iostream>
ID: 247Y1A6790
};
// Circle class derived from Shape
class Circle :public Shape{
public:
void draw() override{
cout << "Drawing a Circle" << endl;
}
};
// Rectangle class derived from Shape
class Rectangle :public Shape{
2024-2028-CSD-B
public:
void draw() override{
cout << "Drawing a Rectangle" << endl;
}
};
// Triangle class derived from Shape
class Triangle :public Shape{
int main() {
int choice;
// User prompt
cout << "Choose a shape to draw:" << endl;
cout << "1. Circle" << endl;
cout << "2. Rectangle" << endl;
cout << "3. Triangle" << endl;
cin >> choice;
ID: 247Y1A6790
shape = new Rectangle(); // Instantiate Rectangle
break;
case 3:
shape = new Triangle(); // Instantiate Triangle
break;
default:
cout << "Invalid choice" << endl;
return 1;
}
2024-2028-CSD-B
// Polymorphic behavior: draw the selected shape
drawShape(*shape);
return 0;
}
User Output
Choose a shape to draw:
1. Circle
2. Rectangle
3. Triangle
1
Drawing a Circle
Test Case - 2
User Output
Choose a shape to draw:
1. Circle
2. Rectangle
3. Triangle
4
Invalid choice
Marri Laxman Reddy Institute of Technology and Management (Autonomous) 2024-2028-CSD-B ID: 247Y1A6790 Page No: 333
Exp. Name: Simulating Sounds of Date: 2025-01-
S.No: 128
Aim:
You are tasked with writing a program that simulates the sounds of different animals. The
program should implement the concept of polymorphism by using an abstract base class
ID: 247Y1A6790
called Animal with a pure virtual function makeSound(). Three animal types are
provided: Dog, Cat, and Cow, and each animal makes a different sound. The program
should prompt the user to select one of these animals, and then the program should
print the respective sound for that animal using polymorphism.
Requirements:
Abstract Base Class Animal:
Define a class Animal that contains a pure virtual function makeSound(). This function
will be overridden by the derived classes.
2024-2028-CSD-B
Derived Classes (Dog, Cat, Cow):
Each derived class (Dog, Cat, and Cow) should inherit from Animal and implement the
makeSound() method to print the sound specific to each animal:
• Dog: prints "Woof".
• Cat: prints "Meow".
• Cow: prints "Moo".
Output Format:
The output should be the sound of the selected animal:
• For Dog, print "Woof".
• For Cat, print "Meow".
• For Cow, print "Moo".
• If the user enters an invalid choice (anything other than 1, 2, or 3), print "Invalid
choice".
Source Code:
animalSounds.cpp
#include <iostream>
ID: 247Y1A6790
};
// Dog class derived from Animal
class Dog :public Animal{
public:
void makeSound() const override{
cout << "Woof" <<endl;
}
};
// Cat class derived from Animal
class Cat:public Animal {
2024-2028-CSD-B
public:
void makeSound() const override{
cout<< "Meow" << endl;
}
};
// Cow class derived from Animal
class Cow:public Animal {
int main() {
int choice;
ID: 247Y1A6790
case 2:
animal = new Cat(); // Create a Cat object
break;
case 3:
animal = new Cow(); // Create a Cow object
break;
default:
cout << "Invalid choice" << endl;
return 1;
}
2024-2028-CSD-B
// Simulate the sound of the chosen animal
simulateSound(*animal);
return 0;
}
User Output
Choose an animal to simulate its sound:
1. Dog
2. Cat
3. Cow
1
Woof
Test Case - 2
User Output
Choose an animal to simulate its sound:
1. Dog
2. Cat
4
3. Cow
Invalid choice
Marri Laxman Reddy Institute of Technology and Management (Autonomous) 2024-2028-CSD-B ID: 247Y1A6790 Page No: 337
Exp. Name: Managing Different Types of Date: 2025-01-
S.No: 129
Aim:
You are tasked with creating a system that manages different types of vehicles (Car, Bus,
and Bicycle). Each vehicle should perform specific operations based on its type. Use
ID: 247Y1A6790
polymorphism to handle the operations uniformly.
Class Specifications:
Base Class Vehicle
• A pure virtual function move(int value)
Derived Classes:
Car:
• Atrribute: speed : initialized to 0
• The car should increase its speed by a specified value each time the move()
2024-2028-CSD-B
function is called.
Bus:
• Atrribute: passengers : initialized to 0
• The bus should load passengers. Each time the move() function is called, it loads
a specific number of passengers.
Bicycle:
Input Format:
The user will input an integer corresponding to the type of vehicle:
• 1 for Car
• 2 for Bus
• 3 for Bicycle
After choosing the vehicle, the user will input an integer that represents the value to
operate on:
• For the Car: Input a number to increase its speed.
• For the Bus: Input a number to load passengers.
• For the Bicycle: Input a number to increase its gear.
Output Format:
After the operation is performed, print the updated status for that vehicle:
• Car: "The car is now moving at [speed] km/h"
• Bus: "The bus now has [passengers] passengers"
• Bicycle: "The bicycle is now in gear [gear]"
transportPolymorphism.cpp
ID: 247Y1A6790
2024-2028-CSD-B
Marri Laxman Reddy Institute of Technology and Management (Autonomous)
#include <iostream>
ID: 247Y1A6790
// Car class derived from Vehicle
class Car:public Vehicle{
private:
int speed;
public:
Car() : speed(0) {}
void move(int value) override{
speed+=value;
cout << "The car is now moving at " << speed << " km/h" <<
endl;
2024-2028-CSD-B
}
};
// Bus class derived from Vehicle
class Bus:public Vehicle{
private:
int passengers;
public:
ID: 247Y1A6790
cout << "2. Bus" << endl;
cout << "3. Bicycle" << endl;
cin >> choice;
2024-2028-CSD-B
// Based on the choice, create the appropriate vehicle object
switch(choice) {
case 1:
vehicle = new Car(); // Create a Car object
break;
case 2:
ID: 247Y1A6790
Enter a value for the operation:
40
The car is now moving at 40 km/h
Test Case - 2
User Output
Choose a vehicle to simulate its operation:
1. Car
2024-2028-CSD-B
2. Bus
3. Bicycle
2
Enter a value for the operation:
16
The bus now has 16 passengers
User Output
Choose a vehicle to simulate its operation:
1. Car
2. Bus
3. Bicycle
3
Enter a value for the operation:
1
The bicycle is now in gear 2
Exp. Name: A System for Sending
Date: 2025-01-
Aim:
ID: 247Y1A6790
You are tasked with designing a notification system that sends notifications through
different mediums such as Email, SMS, and Push Notification. To achieve this, you should
define a base class called Notification with an abstract method send(). Each type of
notification (Email, SMS, Push) will implement its own send() method. The system will
be able to send notifications through any medium using the same interface, ensuring
polymorphism.
Program Requirements:
Base Class Notification:
• Define an abstract class Notification with a pure virtual function send(const
2024-2028-CSD-B
string& message) that all the derived classes will override.
Polymorphism:
• The system should allow sending notifications through different mediums using
the same interface. The method send() should be called on a reference or
pointer of the base class Notification.
Input Format:
The user will input an integer corresponding to the notification medium:
• 1 for Email
• 2 for SMS
• 3 for Push Notification
The user will also input the content of the message they want to send.
Output Format:
After the user inputs their choice and message, the system should send the notification
and print:
• For Email: "Email sent: [message]"
• For SMS: "SMS sent: [message]"
• For Push Notification: "Push Notification sent: [message]"
Source Code:
notifications.cpp
Marri Laxman Reddy Institute of Technology and Management (Autonomous) 2024-2028-CSD-B ID: 247Y1A6790 Page No: 344
#include <iostream>
ID: 247Y1A6790
};
// EmailNotification class derived from Notification
class EmailNotification:public Notification {
public:
void send(const string& message)override{
cout << "Email sent: "<< message << endl;
}
};
// SMSNotification class derived from Notification
class SMSNotification:public Notification{
2024-2028-CSD-B
public:
void send(const string& message)override{
cout << "SMS sent: " <<message<<endl;
}
};
// PushNotification class derived from Notification
class PushNotification:public Notification{
int main() {
int choice;
string message;
ID: 247Y1A6790
//cout << "Enter your message: ";
getline(cin, message);
2024-2028-CSD-B
EmailNotification object
break;
case 2:
notification = new SMSNotification(); // Create an
SMSNotification object
break;
case 3:
User Output
Choose a notification medium:
1. Email
2. SMS
ID: 247Y1A6790
Test Case - 2
User Output
Choose a notification medium:
1. Email
2. SMS
3. Push Notification
2
2024-2028-CSD-B
Recharged Successfully
SMS sent: Recharged Successfully
Test Case - 3
User Output
Aim:
You are tasked with creating a system that simulates a document editor which can handle
different types of documents such as TextDocuments, Spreadsheets, and Presentations.
ID: 247Y1A6790
The system should allow the user to save documents using their respective saving
mechanisms.
To achieve this, you need to:
2024-2028-CSD-B
• TextDocument: Implements the save() method to simulate saving a text
document.
• Spreadsheet: Implements the save() method to simulate saving a spreadsheet.
• Presentation: Implements the save() method to simulate saving a
presentation.
User Input:
Input Format:
The user will input an integer to select the document type:
• 1 for TextDocument
• 2 for Spreadsheet
• 3 for Presentation
After selecting a document type, the user will input the filename for the document.
Output Format:
After the user provides the document type and filename, the system will simulate saving
the document and print the corresponding save message:
• For TextDocument: "Saving text document [filename]"
• For Spreadsheet: "Saving spreadsheet [filename]"
• For Presentation: "Saving presentation [filename]"
• If the user enters an invalid choice, print "Invalid choice".
Source Code:
typeOfDocument.cpp
Marri Laxman Reddy Institute of Technology and Management (Autonomous) 2024-2028-CSD-B ID: 247Y1A6790 Page No: 349
#include <iostream>
ID: 247Y1A6790
};
// Derived class TextDocument
class TextDocument:public Document{
public: void save(const string& filename) override{
cout << "Saving text document " <<filename <<endl;
}
};
// Derived class Spreadsheet
class Spreadsheet:public Document{
public:
2024-2028-CSD-B
void save(const string& filename) override{
cout << "Saving spreadsheet " << filename << endl;
}
};
// Derived class Presentation
class Presentation:public Document{
public:
int main() {
int choice;
string filename;
ID: 247Y1A6790
// Create an object of the appropriate type
Document* doc = nullptr;
2024-2028-CSD-B
break;
case 3:
doc = new Presentation(); // Create a Presentation object
break;
default:
cout << "Invalid choice" << endl;
return 1;
return 0;
}
User Output
Choose a document type to save:
1. TextDocument
2. Spreadsheet
3. Presentation
1
Saving text document file.txt
User Output
Choose a document type to save:
ID: 247Y1A6790
1. TextDocument
2. Spreadsheet
3. Presentation
2
data.xlsx
Saving spreadsheet data.xlsx
2024-2028-CSD-B
Marri Laxman Reddy Institute of Technology and Management (Autonomous)
Exp. Name: Audio Effects Processing Date: 2025-01-
S.No: 132
Aim:
You are tasked with developing a simple audio processing library that applies three basic
audio effects (Reverb, Echo, and Distortion) to a given audio signal. The audio signal is
ID: 247Y1A6790
represented as a sequence of floating-point numbers, where each number corresponds
to the amplitude of the audio at a specific point in time.
In this program, you will define an abstract base class AudioEffect with a virtual
method apply(), and three subclasses: ReverbEffect, EchoEffect, and
DistortionEffect, which will override the apply() method. Each subclass will
perform a simple operation on the audio signal. The goal is to process the audio signal by
applying these three effects in sequence: Reverb, Echo, and Distortion. After applying all
effects, you should display the original and modified audio signal.
2024-2028-CSD-B
Requirements:
• The AudioEffect class will be the abstract base class with a virtual apply()
method.
• The ReverbEffect subclass should override apply() to add 0.1f to each
sample of the audio signal.
• The EchoEffect subclass should override apply() to subtract 0.05f from each
sample of the audio signal.
Input Format:
• The first input is the number of samples in the audio signal.
• The user provides the audio signal samples as floating-point numbers, one for
each sample.
Output Format:
• After receiving the audio samples, the original audio signal should be printed
(space-separated).
• After applying the three effects (Reverb, Echo, and Distortion) in sequence, the
modified audio signal should be printed (space-separated).
Source Code:
audioEffects.cpp
#include <iostream>
ID: 247Y1A6790
virtual void apply(vector<float>& audioSignal)=0;
virtual ~AudioEffect() {}
};
// Subclass for Reverb effect
class ReverbEffect:public AudioEffect{
public:
void apply(vector<float>& audioSignal)override{
for(auto& sample : audioSignal){
sample+=0.1f;
}
2024-2028-CSD-B
}
};
// Subclass for Echo effect
class EchoEffect:public AudioEffect {
public:
void apply(vector<float>& audioSignal)override{
for(auto& sample : audioSignal){
int main() {
size_t signalSize;
//cout << "Enter the number of samples in your audio signal: ";
cin >> signalSize;
// Get the audio signal from the user
ID: 247Y1A6790
}
2024-2028-CSD-B
AudioEffect* effect1 = new ReverbEffect();
AudioEffect* effect2 = new EchoEffect();
AudioEffect* effect3 = new DistortionEffect();
return 0;
}
User Output
4
0.1
3
0.7
0.6
0.2
0.3
0.4
-0.1
User Output
Test Case - 2
Marri Laxman Reddy Institute of Technology and Management (Autonomous) 2024-2028-CSD-B ID: 247Y1A6790 Page No: 356
Exp. Name: Character Attack Simulation Date: 2025-01-
S.No: 133
Aim:
You are tasked with creating a simple simulation program for an RPG-style game. The
game includes different types of characters, each having a specific type of attack. The
ID: 247Y1A6790
goal of the simulation is to model the attack and how it affects the health of the character
performing the attack.
Requirements:
2024-2028-CSD-B
• Virtual function attack(): This function can be overridden by derived classes to
provide specific attack behavior. By default, it outputs "Character attacks!".
• getHealth() const: This function returns the current health of the character,
allowing access to the health attribute.
• decreaseHealth(int amount):This function decreases the character's health
by a specified amount. It ensures that health does not fall below zero.
Mage: A character with high intelligence who casts powerful spells. The damage dealt by
the Mage depends on their intelligence.
• Attribute intelligence (int): holds the mage's intelligence, which
determines the damage dealt during an attack.
• Constructor Mage(int i): This constructor initializes a Mage object with the
specified intelligence i.
• Override of the attack() function: This overridden method calculates the
damage based on the mage's intelligence. Damage Formula:
Damage = I ntelligence ∗ 8
Archer: A character that uses arrows to attack. The damage dealt by the Archer is fixed
ID: 247Y1A6790
has arrows available. If arrows are available, it calculates the damage using the
Damage Formula: Damage = 6 ∗ N umber of Arrows (Each arrow deals 6
points of damage)
Characteristics:
• Each character starts with an initial health of 100 points.
• After each attack, the health of the character performing the attack decreases by
the damage dealt.
• The Archer has a limited number of arrows, and they lose 1 arrow after each attack.
2024-2028-CSD-B
Input Format:
The user will first choose a character by entering a number from 1 to 3:
• 1 for Warrior
• 2 for Mage
• 3 for Archer
Based on the selected character, the user will input the relevant attribute:
• Warrior: Enter the Warrior's strength.
Output Format:
• Display the damage dealt by the attack.
• After the attack, show the remaining health of the character (starting at 100
points).
Source Code:
characterSimulation.cpp
#include <iostream>
ID: 247Y1A6790
Character():health(100){}
virtual void attack(){
cout << "Character attacks!" << endl;
}
void decreaseHealth(int amount){
health-=amount;
if(health<0){
health=0;
}
}
2024-2028-CSD-B
int getHealth() const{
return health;
}
};
// Derived class Warrior
class Warrior:public Character {
private:
ID: 247Y1A6790
void attack() override{
if(arrows>0){
int damage=arrows*6;
arrows--;
cout<<damage<<endl;
cout<<100-damage<<endl;
decreaseHealth(damage);
}
else{
cout << "No arrows left!" <<endl;
2024-2028-CSD-B
}
}
};
void performAttack(Character* character) {
character->attack();
}
Warrior warrior(strength);
performAttack(&warrior);
}
else if (choice == 2) {
//cout << "Enter Mage's intelligence: ";
cin >> intelligence;
ID: 247Y1A6790
cin >> arrows;
Archer archer(arrows);
performAttack(&archer);
}
else {
cout << "Invalid choice" << endl;
}
return 0;
2024-2028-CSD-B
}
Test Case - 2
User Output
Choose a character to attack:
1. Warrior
2. Mage
3. Archer
5
3
70
30
20
80
10
2. Mage
3. Archer
1. Warrior
User Output
Choose a character to attack:
Test Case - 3
Marri Laxman Reddy Institute of Technology and Management (Autonomous) 2024-2028-CSD-B ID: 247Y1A6790 Page No: 362
Exp. Name: File Operations with Date: 2025-01-
S.No: 134
Aim:
You are required to implement a C++ program that reads data from a file. The program
must handle errors that might occur when the file does not exist or when the application
ID: 247Y1A6790
lacks permissions to open the file. Use exception handling (try-catch blocks) to handle
these specific exceptions.
File Reading:
• The user will input the name of a file they wish to read.
• The program should attempt to open the file and read its contents line by line.
Exception Handling:
• If the file does not exist or the application lacks the necessary permissions to read
the file, the program should print an error message: "Error: File does not exist or
2024-2028-CSD-B
cannot be opened".
• If the file is successfully opened and read, the program should print its contents
line by line.
Input Format:
• The program will first ask the user to input the file name they wish to read.
fileExceptions.cpp
#include<iostream>
ID: 247Y1A6790
cin >> filename;
try{
ifstream file(filename);
if(!file.is_open()){
throw runtime_error("File does not exist or cannot be opened");
}
string line;
while(getline(file,line)){
cout << line << endl;
}
2024-2028-CSD-B
file.close();
}
catch(const runtime_error& e){
cout << "Error: " << e.what() << endl;
}
return 0;
}
Hello
World
file2.txt
How
Are
You
demo.txt
Programming in C++
Execution Results - All test cases have succeeded!
User Output
file1.txt
ID: 247Y1A6790
Hello
World
Test Case - 2
User Output
demo1.txt
Error: File does not exist or cannot be opened
2024-2028-CSD-B
Marri Laxman Reddy Institute of Technology and Management (Autonomous)
Exp. Name: E-Commerce Checkout Date: 2025-01-
S.No: 135
Aim:
You are tasked with implementing the checkout process for an e-commerce application.
The system should process user orders and handle errors such as invalid payment details,
ID: 247Y1A6790
out-of-stock items, and delivery address issues. The program should use exception
handling to manage these errors effectively.
Order Details:
• The user places an order by selecting items and providing payment and delivery
details.
• Each order has a set of items, a payment method, and a delivery address.
Exception Handling:
• Invalid Payment Details: If the user enters invalid payment details (e.g., incorrect
2024-2028-CSD-B
card number or expired card), the system should throw an exception and print an
appropriate error message.
• Out-of-Stock Items: If the user attempts to purchase an item that is out of stock,
the system should throw an exception and print an error message indicating that
the item is unavailable.
• Invalid Delivery Address: If the user enters an invalid delivery address (e.g.,
incomplete or incorrect address), the system should throw an exception and notify
Input Format:
The user will enter the number of items they wish to purchase.
For each item, the user will provide:
• Item name
• Quantity
• Availability (in stock - 0 or out of stock - 1)
The user will also provide:
• Payment details (e.g., card number)
• Delivery address (valid or invalid)
Output Format:
If the checkout process is successful, print a message: "Order processed successfully".
If an error occurs during the process, print an appropriate error message:
• "Error: Invalid payment details".
• "Error: Item out of stock".
• "Error: Invalid delivery address".
Constraints:
• Assume the card number must be 16 digits long for a valid payment.
• If any item in the order is out of stock, the order should not be processed, and the
user should be notified immediately.
checkout.cpp
ID: 247Y1A6790
2024-2028-CSD-B
Marri Laxman Reddy Institute of Technology and Management (Autonomous)
#include <iostream>
ID: 247Y1A6790
details"){}
};
class OutOfStockException : public std::runtime_error {
public:
OutOfStockException():runtime_error("Error: Item out of stock"){}
};
class InvalidAddressException : public std::runtime_error {
public:
InvalidAddressException():runtime_error("Error: Invalid delivery
address"){}
2024-2028-CSD-B
};
void validatePayment(const string& cardNumber){
if(cardNumber.length()!=16){
throw InvalidPaymentException();
}
}
void validateAddress(const string& address){
string itemName;
int quantity;
string availability;
bool allItemsInStock = true;
ID: 247Y1A6790
// Check if all items are in stock
try {
if(!allItemsInStock){
throw OutOfStockException();
}
// Collect payment details
string cardNumber;
cin >> cardNumber;
// Validate payment details
validatePayment(cardNumber);
2024-2028-CSD-B
// Collect delivery address
string deliveryAddress;
cin.ignore(); // To clear the input buffer
getline(cin, deliveryAddress);
// Validate delivery address
validateAddress(deliveryAddress);
// If no exceptions occurred, process the order
User Output
1
Item 1:
Laptop
2
Test Case - 2
ID: 247Y1A6790
User Output
2
Item 1:
Mouse
1
0
Item 2:
Umbrella
2024-2028-CSD-B
2
0
1234567890
Error: Invalid payment details
User Output
1
Item 1:
Handbag
1
0
1234567890112233
india
Error: Invalid delivery address
Test Case - 4
User Output
1
Item 1:
Shoes
0
1
gandhiNagar,Delhi
0987654321234567
Marri Laxman Reddy Institute of Technology and Management (Autonomous) 2024-2028-CSD-B ID: 247Y1A6790 Page No: 371