0% found this document useful (0 votes)
48 views

CP Assignment

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views

CP Assignment

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Computer Programming Lab Assignments

B.Tech. (2024-25 Session)


Module-1

Write C programs for the following questions:

1. Find the area of a circle.


2. Enter the length and breadth of a rectangle and find the area.
3. Find the average of 3 entered numbers.
4. Enter the CGPA obtained by a student and find the equivalent percentage of marks.
5. Swap the values of two variables using a third variable.
6. Swap the values of two variables without using a third variable.
7. Find the sum of the individual digits of any entered three-digit positive number.
8. Enter the principal, time, and rate of interest. Calculate the simple interest.
9. Convert any input temperature in Fahrenheit to Celsius.
10. Find the percentage of marks obtained by a student by entering the marks secured by the student
in 5 subjects. Consider the total mark in each subject is 100.
11. Calculate the gross salary of an employee by entering the basic salary. DA is 42%, HRA is 30%
of the basic salary and a fixed other allowance (OA) of Rs. 2000. (Gross salary=Basic+
DA+HRA+OA)
12. Convert an input total number of days into corresponding number of years, months and remaining
days. Consider 1 month=30 days.
(Example- Input days: 450 days; Output: 1 year, 2 months, 25 days)
13. Input some quantity weight in grams and calculate the corresponding weight in Kilograms and
remaining grams (Example- Input weight: 1500 grams; Output: 1 KG 500 grams)
14. Input the time in seconds and calculate the corresponding hours, minutes, and remaining seconds.
(Exa: Input time in seconds: 3665; Output: 1 Hour 1 minute 5 seconds).
15. Calculate the distance between two points (x1, y1) and (x2, y2) for any entered values of x1,y1
and x2, y2.
16. Calculate area of a triangle by Herron’s method for any entered values of a, b and c.
17. Print the size of various basic data types (char, int, float, double) in C.
18. Calculate the total bill to be paid by a customer entering the price of 3 products and their
quantities. Include a 10% tax on total bill amount for calculation of the amount to be paid by the
customer.
19. Find the smallest number among three entered numbers using conditional operator.
20. Enter the total price of some food order by a customer in a restaurant. The restaurant charges a
12% GST on total amount. If the total amount exceeds RS 1000, the restaurant offers a 5%
discount. Otherwise no discount is provided. Use conditional operator for discount calculation.
Print the final amount payable by the customer.
Module-II

Decision making and Branching:

Write C programs for the following questions:

1. Find greatest among two entered numbers.


2. Check whether an entered number is even or odd.
3. Check whether an entered character is a vowel or not.
4. Check whether an entered number is divisible by 3 and 5.
5. Check whether an entered year is a leap year or not.
6. Check whether any entered number is positive, negative or zero using nested if-else statement
7. Check whether two entered numbers are equal or the first number is greater than the second
number or the second number is greater than the first number using nested if-else statement.
8. Find greatest among 3 entered numbers using nested if-else statement.
9. Find smallest among three entered numbers using else if ladder. Use logical AND operator to
combine multiple conditions.
10. Enter mark obtained by a student in a subject and print the respective grade using else-if ladder
statement. Consider the following grading system:
Score out of 100 Marks Grade
90 & above up to 100 O
80 & above but less than 90 E
70 & above but less than 80 A
60 & above but less than 70 B
50 & above but less than 60 C
40 & above but less than 50 D
Less than 40 or Absent in Exam U
11. Enter the cost price and selling price of a product and check profit or loss. Also, print the
percentage of loss or profit for the product.
12. Compute the real roots of a quadratic equation ax2 + bx + c=0 (given a, b and c) for the following
conditions:
i) No solution, if both a and b are zero.
ii) Only one root if determinant (b2 - 4ac)=0
iii) No real roots if b2 - 4ac < 0
iv) Otherwise there are 2 real roots

13. Calculate the income tax payable by a person by entering the total taxable income as per the
below slabs:
Taxable Income range (in RS) Tax%
0 – 3,00000 0
3,00001 – 7,00000 5
7,00001- 10,00000 10
10,00001- 12,00000 15
12,00001 – 15,00000 20
Greater than 15,00000 30

14. Calculate the age of a person, given date of birth (DOB) and current date (CD). A date is
represented as three integers (say dd, mm, and yyyy). The result to be printed as YY years, MM
months, DD days. Consider a month consist of 30 days.
Example: Input DOB: 29/10/1980, CD: 27/8/2011
Output: Age: 30 years 9 Months and 28 days
15. Enter the total purchase amount for a customer and calculate the amount payable by the customer
after discount, if a shopping mall announced the following discounts on total purchase amount:
Purchase amount (RS) Discount
< 1000 -
1000-3000 5%
3001-6000 7%
6001-10000 10%
Above 10000 Rs 2000
16. Enter the previous month and current month meter reading. Calculate the electric bill amount for
any customer as per the following rules:
First 100 units : Rs 3.20 per unit.
Next 200 units : Rs 5.40 per unit.
Remaining units : Rs 6 per unit
17. Given a number between 1 to 7, print the day name (Monday- Sunday) using switch-case
statement.
18. Given a number 0-9, print the corresponding English word for the number using switch-case
statement.
19. Check whether an entered character is a vowel or not using switch-case statement.
20. Create a menu-driven program using switch–case statement that will ask the user to enter two
numbers and an operator (+, -, *, /). When the user enters a valid choice, the program prints the
result of the respective operation as per the entered choice, otherwise prints an error message.
Loops:

Write C programs for the following questions:

1. Print first n natural numbers using while loop.


2. Print the multiplication table of any entered number.
3. Find sum of digits of an entered number using while loop.
4. Find Fibonacci series up to an entered number using do-while loop.
Test data: Entered number=90
Output series: 0 1 1 2 3 5 8 13 21 34 55 89
5. Find the sum of all user entered numbers until the sum exceeds 100 using do while loop.
6. Find the factorial of any user entered number using for loop.
7. Find the GCD of two entered numbers.
8. Print all odd numbers in a given range.
9. Find sum of all even numbers in a given range.
10. Check whether an entered number is a prime or composite number.
11. Check whether an entered number is a palindrome number or not.
12. Check whether an entered number is an Armstrong number or not.
13. Print all natural numbers in descending order up to 1 from an entered number except the numbers
divisible by 7 (use continue statement)
14. Display the binary equivalent of an entered decimal number.
15. Display the decimal equivalent of an entered binary number.
16. Print the following pattern:
12345
1234
123
12
1
17. Print the following pattern:
A
AB
ABC
ABCD
ABCDE
ABCDEF
18. Print the following pattern:
1
123
12345
1234567
19. Print the following pattern:
1
00
111
0000
11111
20. Print the following pattern:
1
121
12321
21. Print the following pattern:
* * * * *
* * *
*
22. Print all prime numbers in a given range.
23. Print all palindrome numbers in a given range.
24. Print all Armstrong numbers in a given range.
25. Print all numbers in a range that are divisible by 5 and 7

You might also like