C Programming

Solved Example

Practice Questions

Exercise Question

Calculate the library penalty charges


Input the number of days from the issue date of a book. A library decided to penalty charges on an issuing book after 7 days of issue. The penalty charges are as given below

  1. For the first five delays, 50 paise/day.
  2. For delay of 6-20 days, 1 Rs/day.
  3. For delay of 20-30 days, 5 Rs/day.
  4. For delay more than 30 days, 10 Rs/day.

Calculate the penalty charges of the book.

Program / Solution:

int main() {
	int days,delay;
	float penalty ;
	printf("Enter the issue days of a book: ");
	delay = days - 7;
	if(delay <= 0) {
		penalty = 0;
	}else if(delay <= 5) {
		penalty = delay * 0.50f;
	}else if(delay <= 20) {
		penalty = delay * 1;
	}else if(delay <= 30) {
		penalty = delay * 5;
	}else {
		penalty = delay * 10;
	printf("Issue days = %d\n",days);
	printf("Delay days = %d\n",delay);
	printf("Penalty = %.2f\n",penalty);
	return 0;

Sample Output:

Enter the issue days of a book: 25
Issue days = 25
Delay days = 18
Penalty = 18.00

More Progarms of Decision Making in C

Calculate profit or loss

Check a number is even or odd

Check a number is positive or negative

Check a year is leap year or not

Find the first day of year

Find the youngest person

Absolute value of a number

Find area of rectangle is greater than perimeter

Check the points are co-linear or not

Check a point is inside,outside or on the circle

Check the axis of a point

Identify a character is alphabet, digit and more

Check the insurance eligibility and calculate premium

Calculate grade of a student