0% found this document useful (0 votes)
24 views11 pages

CO6 - Lab Exercises

Uploaded by

vmahescse
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views11 pages

CO6 - Lab Exercises

Uploaded by

vmahescse
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

NATIONAL ENGINEERING COLLEGE, K.R.

NAGAR, KOVILPATTI – 628 503


(An Autonomous Institution Affiliated to Anna University, Chennai)
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
Regulation 2023
23CS11C – Problem Solving Techniques
Lab Exercises – Odd Semester – 2025 - 2026

CO6: develop programs for simple algorithms using sequential and Control structures.
Level: Easy
1. Write a C program that accepts two integers and prints Yes if at least one of the two
integers is even. Else the program prints No.
2. Write a C program that must accept four integers and find the remainder when the
second integer is divided by the third integer as R1. Then the program must find the
remainder when the first integer is divided by the fourth integer as R2. Finally the
program must print the quotient when R1 is divided by R2.
3. Write a C program that must accept four integers and subtract the third integer from the
fourth integer from the second integer as D1. Then the program must subtract the first
integer from the second integer as D2. Finally, the program must print the quotient
when D1 is divided by D2.
4. Write a C program that accepts an alphabet and prints the position of the alphabet. (e.g.,
'a' = 1, 'y' = 25).
5. Write a C program that accepts the age of a customer as an input. If the age is greater
than or equal to 60, the program must print senior else program must print NotSenior.
6. Write a C program that accept the length L and breadth B of a rectangle is passed as
input. If L is equal to B, the program must print SQUARE. Else the program must print
RECTANGLE.
7. Write a C program that accepts two numbers M and N are passed as the input. The
program must print the numbers divisible by 15 from M to N.
Input:
2
40
Output:
15 30
8. Write a program that accepts the input name N of the athlete and the number of medals
M won by the athlete in a games Tournament are passed as the input, the program must
print the message as N won M medals.
Input:
Phelps
5
Output:
Phelps won 5 medals
9. The program must accept principal amount P, interest rate R and time period in years
N as the input. The program must calculate and print the simple interest value as the
output with precision upto decimal places. Formula: SI = P*N*R/100
Example Input/Output 1:
Input: 10000 12 5
Output: 6000.00
Example Input/Output 2:
Input: 1000 5 2
Output: 100.00

10. Write a C program that accepts a string and prints the summation of the ASCII values
of its characters.
Input Format
abcd
Output Format
394

Level: Medium

1. Write a program that reads the number of units consumed and calculates the total
electricity bill using the above slab rates. You're tasked with developing a billing system
for an electricity company. The system needs to calculate the total bill amount based on
the units of electricity consumed. The pricing is tiered:
● The first 100 units are charged at $1.5 per unit.
● The next 100 units (101 to 200) are charged at $2.5 per unit.
● The next 100 units (201 to 300) are charged at $4 per unit.
● Units beyond 300 are charged at $5 per unit.

The program should output the total bill amount based on the consumption.
Example Input/Output :
Input: Enter the number of units consumed: 250
Output: Total electricity bill: $475.00

2. Write a program that takes the student’s score as input and prints the corresponding
grade according to the given criteria. You are designing a simple grading system for
a school. The system should assign a grade based on a student's exam score. The
grading criteria are:
● 90 and above: Grade A
● 80 to 89: Grade B
● 70 to 79: Grade C
● 60 to 69: Grade D
● Below 60: Grade F
The program should output the student's grade.
Example Input/Output :
Input: Enter marks (out of 100): 85
Output: Grade: B
3. Write a program that accepts the loan amount (principal), annual interest rate, and
tenure (in years), then calculates and displays the monthly EMI. A finance company
needs to calculate the Equated Monthly Installment (EMI) for loans. The EMI is
calculated using the following formula:

where:

● P is the principal loan amount,


● r is the monthly interest rate (annual rate divided by 12),
● n is the number of monthly installments (loan tenure in years multiplied by 12).

The program should output the calculated EMI.


Example Input/Output :
Input:
Enter principal amount: 50000
Enter annual rate of interest (in percentage): 7
Enter tenure (in years): 5
Output: Monthly EMI: $990.45

4. Write a C program that reads the number of hours a vehicle was parked and calculates
the total parking fee based on the following criteria. you are developing software for
a parking lot that charges fees based on the duration a vehicle is parked. The charges
are as follows:
● Up to 2 hours: $5 per hour
● 3 to 5 hours: $10 for the first 2 hours, and $4 for each additional hour
● 6 to 10 hours: $22 for the first 5 hours, and $3 for each additional hour
● More than 10 hours: $37 for the first 10 hours, and $2 for each additional hour

The program should output the total parking charge.

Example Input/Output :
Input: Enter number of hours parked: 7
Output: Total parking charge: $28.00

5. Write a program that prompts the user to select the conversion type (Celsius to
Fahrenheit or Fahrenheit to Celsius), inputs the temperature, and then performs the
conversion and displays the result. You need to develop a utility for converting
temperatures between Celsius and Fahrenheit. Users should be able to input a
temperature in one scale and convert it to the other scale.

The formulas for conversion are

The program should output the converted temperature


Example Input/Output :
Input:
Choose conversion type:
1. Celsius to Fahrenheit
2. Fahrenheit to Celsius
Enter choice: 1
Enter temperature in Celsius: 25
Output: Temperature in Fahrenheit: 77.00°F

6. Write a program that accepts the annual income of an individual and calculates the
total tax payable based on the given slabs. A tax calculation program is needed for an
individual based on their annual income. The tax rates are progressive:
● Income up to $10,000: No tax
● Income from $10,001 to $20,000: 10% tax
● Income from $20,001 to $50,000: 20% tax
● Income above $50,000: 30% tax

The program should output the calculated tax.


Example Input/Output :
Input:
Enter annual income: 45000
Output: Total tax payable: $6000.00

7. Write a C program that takes the withdrawal amount in rupees and calculates the
number of each denomination required to fulfill the request. Simulate an ATM
withdrawal process in Indian Rupees. The ATM should dispense the smallest number
of bills possible for a given withdrawal amount using the denominations ₹500, ₹200,
₹100, ₹50, ₹20 and ₹10.
The program should output the number of each denomination dispensed.
Example Input/Output :
Input:
Enter the withdrawal amount in rupees: 3780
Output:
₹500 notes: 7
₹200 notes: 1
₹100 notes: 0
₹50 notes: 1
₹20 notes: 1
₹10 notes: 1
8. Write a C program that accepts a gallon number to calculate the total water bill based on the
number of gallons consumed. The pricing structure is as follows:
First 1000 gallons: $1 per gallon
Next 1000 gallons (1001 to 2000): $1.5 per gallon
Beyond 2000 gallons: $2 per gallon
Input Example:
Enter the number of gallons consumed: 2500
Output Example:
Total water bill: $3500.00
9. Write a C program that accepts an annual salary to calculate the income tax for an individual
based on the following salary brackets:
Up to $30,000: No tax
$30,001 to $60,000: 10% tax
$60,001 to $100,000: 20% tax
Above $100,000: 30% tax
Input Example:
Enter the annual salary: 75000
Output Example:
Total tax payable: $9000.00
10. Write a C program that accepts weight (in kg) and height (in meters) to calculate the Body
Mass Index (BMI) and classify the health condition.
BMI < 18.5: Underweight
18.5 <= BMI < 24.9: Normal weight
25 <= BMI < 29.9: Overweight
BMI >= 30: Obese
Input Example:
Enter weight in kg: 70
Enter height in meters: 1.75
Output Example:
BMI: 22.86 (Normal weight)
11. Write a C program that accepts a person's age, monthly salary, and employment status to
check whether the person is eligible for a personal loan based on the following
conditions:
Age should be between 21 and 60
Salary must be more than $25,000
Employment status must be either "permanent" or "contract"
Input Example:
Enter age: 30
Enter monthly salary: 30000
Enter employment status (permanent/contract): permanent
Output Example:
Eligible for loan
12. Write a C program that accepts the principal amount, annual interest rate, and number of
years to calculate the compound interest using the formula:
A = P * (1 + R/100)^N
Input Example:
Enter principal: 10000
Enter interest rate: 5
Enter number of years: 3
Output Example:
Final amount: $11576.25
13. Write a C program that accepts the lengths of three sides of a triangle and determines the
type of triangle:
Equilateral: All sides are equal
Isosceles: Two sides are equal
Scalene: All sides are different
Invalid: If the sides do not form a valid triangle
Input Example:
Enter the lengths of three sides: 3 4 5
Output Example:
The triangle is Scalene
14. Write a C program that accepts two numbers to calculate their greatest common divisor
(GCD) using the Euclidean algorithm.
Input Example:
Enter two numbers: 56 98
Output Example:
GCD of 56 and 98 is 14
15. Write a C program that accepts a number N to print the first N numbers in the Fibonacci
series using a do-while loop.
Input Example:
Enter the number of terms: 7
Output Example:
0112358

Level: Hard

1. A grocery store wants to implement a discount management system for its customers.
The store offers a discount based on the total purchase amount:
● If the total amount is above $500, a discount of 10% is applied.
● If the total amount is between $300 and $500, a discount of 5% is applied.
● If the total amount is less than $300, no discount is applied.

Write a C program to:

● Accept the total purchase amount from the user.


● Calculate the discount based on the given criteria.
● Display the final amount after applying the discount.

Sample Input:

Total Purchase Amount: 450

Sample Output:

Discount Applied: 5%
Final Amount: 427.5

2. A company wants to evaluate the performance of its employees based on their monthly
sales. The performance evaluation is done as follows:
● If the sales are above $10,000, the employee is rated "Excellent".
● If the sales are between $5,000 and $10,000, the employee is rated "Good".
● If the sales are between $1,000 and $5,000, the employee is rated "Average".
● If the sales are below $1,000, the employee is rated "Needs Improvement".

Write a C program that:

1. Accepts the monthly sales figure from the user.


2. Determines and prints the performance rating based on the sales figure.

Sample Input:

Monthly Sales: 7200

Sample Output:

Performance Rating: Good

3. Design a traffic light control system using control structures. The program should:

● Accept the color of the traffic light (Red, Yellow, Green) from the user.
● Print "Stop" if the color is Red.
● Print "Ready to Go" if the color is Yellow.
● Print "Go" if the color is Green.
● Handle invalid color input by printing "Invalid color".

Write a C program to implement this logic.

Sample Input:

Traffic Light Color: Green

Sample Output:

Go

4. A school needs a program to calculate the grade of a student based on their total marks obtained
in five subjects. The grading system is as follows:

● Marks >= 90: Grade "A"


● Marks >= 75 and < 90: Grade "B"
● Marks >= 50 and < 75: Grade "C"
● Marks < 50: Grade "D"

Write a C program to:

1. Accept the marks for five subjects.


2. Calculate the total and percentage.
3. Determine and print the grade based on the percentage.

Sample Input:

Marks in Subject 1: 85
Marks in Subject 2: 78
Marks in Subject 3: 65
Marks in Subject 4: 90
Marks in Subject 5: 70

Sample Output:

Total Marks: 388


Percentage: 77.6
Grade: B

5. A mobile service provider charges customers based on the number of minutes they use their
phone for calls:

● For the first 100 minutes, the rate is $0.5 per minute.
● For the next 100 minutes (101 to 200), the rate is $0.25 per minute.
● For any additional minutes beyond 200, the rate is $0.1 per minute.

Write a C program that:

1. Accepts the total number of minutes used from the user.


2. Calculates the total bill amount based on the usage.
3. Displays the total amount to be paid.

Sample Input:

Total Minutes Used: 250

Sample Output:

Total Bill Amount: $75.0

6. An electricity company charges its customers based on their consumption of electricity units
as follows:

● For the first 100 units: $1 per unit.


● For the next 100 units (101 to 200): $1.5 per unit.
● For units beyond 200: $2 per unit.

Write a C program to:

1. Accept the total number of units consumed from the user.


2. Calculate and display the total bill amount.

Sample Input:

Total Units Consumed: 250

Sample Output:
Total Bill Amount: $325.0

7. A fitness application tracks daily calorie intake. The app categorizes users based on their
daily calorie consumption:

● Below 1500 calories: "Under Consumption"


● Between 1500 to 2500 calories: "Normal Consumption"
● Above 2500 calories: "Over Consumption"

Write a C program to:


1. Accept the daily calorie intake from the user.
2. Determine and print the category of consumption based on the input.

Sample Input:

Daily Calorie Intake: 1800

Sample Output:

Category: Normal Consumption

8. A parking lot charges fees based on the number of hours a vehicle is parked:

● First 2 hours: Free


● Next 3 hours: $5 per hour
● After 5 hours: $10 per hour

Write a C program to:

1. Accept the number of hours the vehicle is parked.


2. Calculate the total parking fee based on the given conditions.
3. Display the total fee to be paid.

Sample Input:

Number of Hours Parked: 7

Sample Output:

Total Parking Fee: $35

9. A health application monitors users' sleep duration to provide feedback on their sleep quality.
The app categorizes sleep quality based on the hours of sleep:

● Below 6 hours: "Insufficient Sleep"


● Between 6 to 8 hours: "Healthy Sleep"
● Above 8 hours: "Oversleeping"

Write a C program to:

● Accept the number of hours the user slept last night.


● Determine and print the sleep quality category based on the input.

Sample Input:

Hours of Sleep: 7

Sample Output:
Category: Healthy Sleep

10. An educational institution tracks students' attendance and provides feedback on their
attendance status. The institution categorizes attendance as follows:

● Below 75%: "Poor Attendance"


● Between 75% to 90%: "Satisfactory Attendance"
● Above 90%: "Excellent Attendance"

Write a C program to:

● Accept the attendance percentage of a student.


● Determine and print the attendance status category based on the input.

Sample Input:

Attendance Percentage: 85

Sample Output:

Category: Satisfactory Attendance

You might also like