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

Practice C Program

The document outlines a series of C programming exercises that cover various mathematical and logical computations, such as calculating areas and perimeters of shapes, converting units, validating conditions, and processing user input. Each exercise includes specific test data and expected output to guide the implementation. The exercises range from basic arithmetic operations to more complex tasks like solving quadratic equations and validating passwords.

Uploaded by

amaldash1992
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)
16 views

Practice C Program

The document outlines a series of C programming exercises that cover various mathematical and logical computations, such as calculating areas and perimeters of shapes, converting units, validating conditions, and processing user input. Each exercise includes specific test data and expected output to guide the implementation. The exercises range from basic arithmetic operations to more complex tasks like solving quadratic equations and validating passwords.

Uploaded by

amaldash1992
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
You are on page 1/ 10

Practice C Program

1. Compute rectangle perimeter and area

Write a C program to compute the perimeter and area of a rectangle with a height of 7 inches and
width of 5 inches.
Expected Output:
Perimeter of the rectangle = 24 inches
Area of the rectangle = 35 square inches

2. Compute circle perimeter and area

Write a C program to compute the perimeter and area of a circle with a given radius.
Expected Output:
Perimeter of the Circle = 37.680000 inches
Area of the Circle = 113.040001 square inches

3. Convert days to years, weeks, and days

Write a C program to convert specified days into years, weeks and days.
Note: Ignore leap year.

Test Data :
Number of days : 1329
Expected Output :
Years: 3
Weeks: 33
Days: 3

3. Calculate sum of two integers

Write a C program that accepts two integers from the user and calculates the sum of the two integers.
Test Data :
Input the first integer: 25
Input the second integer: 38
Expected Output:
Sum of the above two integers = 63

4. Calculate product of two integers

Write a C program that accepts two integers from the user and calculates the product of the two
integers.
Test Data :
Input the first integer: 25
Input the second integer: 15
Expected Output:
Product of the above two integers = 375

5. Calculate average weight for purchases

Write a C program that accepts two item's weight and number of purchases (floating point values) and
calculates their average value.
Test Data :
Weight - Item1: 15
No. of item1: 5
Weight - Item2: 25
No. of item2: 4
Expected Output:
Average Value = 19.444444

6. Print employee ID and monthly salary

Write a C program that accepts an employee's ID, total worked hours in a month and the amount he
received per hour. Print the ID and salary (with two decimal places) of the employee for a particular
month.
Test Data :
Input the Employees ID(Max. 10 chars): 0342
Input the working hrs: 8
Salary amount/hr: 15000
Expected Output:
Employees ID = 0342
Salary = U$ 120000.00

7. Find the maximum of three integers

Write a C program that accepts three integers and finds the maximum of three.
Test Data :
Input the first integer: 25
Input the second integer: 35
Input the third integer: 15
Expected Output:
Maximum value of three integers: 35

8. Calculate bike’s average consumption

Write a C program to calculate a bike’s average consumption from the given total distance (integer
value) travelled (in km) and spent fuel (in litters, float number – 2 decimal points).
Test Data :
Input total distance in km: 350
Input total fuel spent in liters: 5
Expected Output:
Average consumption (km/lt) 70.000

9. Calculate distance between two points

Write a C program to calculate the distance between two points.


Test Data :
Input x1: 25
Input y1: 15
Input x2: 35
Input y2: 10
Expected Output:
Distance between the said points: 11.1803

10. Break amount into smallest banknotes

Write a C program to read an amount (integer value) and break the amount into the smallest possible
number of bank notes.
Test Data :
Input the amount: 375
Expected Output:
There are:
3 Note(s) of 100.00
1 Note(s) of 50.00
1 Note(s) of 20.00
0 Note(s) of 10.00
1 Note(s) of 5.00
0 Note(s) of 2.00
0 Note(s) of 1.00

11. Convert seconds into hours, minutes, seconds

Write a C program to convert a given integer (in seconds) to hours, minutes and seconds.
Test Data :
Input seconds: 25300
Expected Output:
There are:
H:M:S - 7:1:40

12. Convert days to years, months, days

Write a C program to convert a given integer (in days) to years, months and days, assuming that all
months have 30 days and all years have 365 days.
Test Data :
Input no. of days: 2535
Expected Output:
6 Year(s)
11 Month(s)
15 Day(s)

13. Validate four integers based on conditions

Write a C program that accepts 4 integers p, q, r, s from the user where q, r and s are positive and p
is even. If q is greater than r and s is greater than p and if the sum of r and s is greater than the sum
of p and q print "Correct values", otherwise print "Wrong values".
Test Data :
Input the second integer: 35
Input the third integer: 15
Input the fourth integer: 46
Expected Output:
Wrong values

14. Solve quadratic equation using Bhaskara's formula


Write a C program to print the roots of Bhaskara’s formula from the given three floating numbers.
Display a message if it is not possible to find the roots.
Test Data :
Input the first number(a): 25
Input the second number(b): 35
Input the third number(c): 12
Expected Output:
Root1 = -0.60000
Root2 = -0.80000

15. Check integer range or error for negative > 80

Write a C program that reads an integer and checks the specified range to which it belongs. Print an
error message if the number is negative and greater than 80.
Test Data :
Input an integer: 15
Expected Output:
Range [0, 20]

16. Sum all odd numbers among five inputs

Write a C program that reads 5 numbers and sums all odd values between them.
Test Data :
Input the first number: 11
Input the second number: 17
Input the third number: 13
Input the fourth number: 12
Input the fifth number: 5
Expected Output:
Sum of all odd values: 46

17. Check for valid triangle and calculate perimeter

Write a C program that reads three floating-point values and checks if it is possible to make a triangle
with them. Determine the perimeter of the triangle if the given values are valid.
Test Data :
Input the first number: 25
Input the second number: 15
Input the third number: 35
Expected Output:
Perimeter = 75.0

18. Check if two integers are multiples

Write a C program that reads two integers and checks whether they are multiplied or not.
Test Data :
Input the first number: 5
Input the second number: 15
Expected Output:
Multiplied!

19. Get month name from number (1–12)

Write a C program that reads an integer between 1 and 12 and prints the month of the year in
English.
Test Data :
Input a number between 1 to 12 to get the month name: 8
Expected Output:
August

20. Count positive and negative numbers in 5 inputs

Write a C program that reads 5 numbers and counts the number of positive numbers and negative
numbers.
Test Data :
Input the first number: 5
Input the second number: -4
Input the third number: 10
Input the fourth number: 15
Input the fifth number: -1
Expected Output:
Number of positive numbers: 3
Number of negative numbers: 2
21. Count positives and calculate their average from 5 inputs

Write a C program that reads 5 numbers, counts the number of positive numbers, and prints out the
average of all positive values.
Test Data :
Input the first number: 5
Input the second number: 8
Input the third number: 10
Input the fourth number: -5
Input the fifth number: 25
Expected Output:
Number of positive numbers: 4
Average value of the said positive numbers: 12.00

22. Sum all odd values among 5 inputs

Write a C program that read 5 numbers and sum of all odd values between them.
Test Data :
Input the first number: 5
Input the second number: 7
Input the third number: 9
Input the fourth number: 10
Input the fifth number: 13
Expected Output:
Sum of all odd values: 34

23. Print squares of all even numbers up to a given value

Write a C program to find and print the square of all the even values from 1 to a specified value.
Test Data :
List of square of each one of the even values from 1 to a 4 :
Expected Output:
2^2 = 4
4^2 = 16

24. Check if an integer is positive/negative and even/odd


Write a C program to check whether a given integer is positive even, negative even, positive odd or
negative odd. Print even if the number is 0.
Test Data :
Input an integer: 13
Expected Output:
Positive Odd

25. Find the highest value and its position from inputs

Write a C program that accepts some integers from the user and finds the highest value and the input
position.
Test Data :
Input 5 integers:
5
7
15
23
45
Expected Output:
Highest value: 45
Position: 5

26. Sum odd numbers between two given integers

Write a C program to compute the sum of consecutive odd numbers from a given pair of integers.
Test Data :
Input a pair of numbers (for example 10,2):
Input first number of the pair: 10
Input second number of the pair: 2
Expected Output:
List of odd numbers: 3
5
7
9
Sum=24

27. Check if a pair of numbers is in ascending/descending order


Write a C program to check if two numbers in a pair are in ascending order or descending order.
Test Data :
Input a pair of numbers (for example 10,2 : 2,10):
Input first number of the pair: 10
Expected Output:
Input second number of the pair: 2
The pair is in descending order!

27. Validate a password (1234 as correct)

Write a C program to read a password until it is valid. For wrong password print "Incorrect password"
and for correct password print, "Correct password" and quit the program. The correct password is
1234.
Test Data :
Input the password: 1234
Expected Output:
Correct password

28. Determine quadrant of Cartesian coordinates (x, y)

Write a C program to read the coordinates (x, y) (in the Cartesian system) and find the quadrant to
which it belongs (Quadrant -I, Quadrant -II, Quadrant -III, Quadrant -IV).
Note: A Cartesian coordinate system is a coordinate system that specifies each point uniquely in a
plane by a pair of numerical coordinates.
These are often numbered from 1st to 4th and denoted by Roman numerals: I (where the signs of the
(x,y) coordinates are I(+,+), II (−,+), III (−,−), and IV (+,−).
Test Data :
Input the Coordinate(x,y):
x: 25
y: 15
Expected Output:
Quadrant-I(+,+)

29. Divide two numbers or print if division isn't possible

Write a program that reads two numbers and divides the first number by the second number. If
division is not possible print "Division is not possible".
Test Data :
Input two numbers:
x: 25
y: 5
Expected Output: 5.0

30. Sum all numbers between two integers, excluding multiples of 17

Write a C program to calculate the sum of all numbers not divisible by 17 between two given integer
numbers.
Test Data :
Input the first integer: 50 Input the second integer: 99
Expected Output:
Sum: 3521

31. Find integers divisible by 7 with a remainder of 2 or 3

Write a C program that finds all integer numbers that divide by 7 and have a remainder of 2 or 3
between two given integers.
Test Data :
Input the first integer: 25
Input the second integer: 45
Expected Output:
30
31
37
38
44

You might also like