C Programming

Solved Example

Practice Questions

Exercise Question

Check the insurance eligibility and calculate premium

Objective:

An Insurance company follows the following rules to calculate the premium.

  1. If a person’s health is excellent and the person is between 25 and 35 years of age and lives in a city and is a male then the premium is Rs. 4 per thousand and his policy amount cannot exceed Rs. 2 lakhs.
  2. If a person satisfies all the above conditions except that the sex is female then the premium is Rs. 3 per thousand and her policy amount cannot exceed Rs. 1 lakh.
  3. If a person’s health is poor and the person is between 25 and 35 years of age and lives in a village and is a male then the premium is Rs. 6 per thousand and his policy cannot exceed Rs. 10,000.
  4. In all other cases, the person is not insured.

Write a program to output whether the person should be insured or not, his/her premium rate, and maximum amount for which he/she can be insured.

Program / Solution:

#include<stdio.h>
#include<ctype.h>
int main() {
	char gen,health,residence;
	int age;
	
	printf("Enter the gender male/female (M/F): ");
	scanf("%c",&gen);
	
	fflush(stdin);
	printf("Enter the health excellent/poor(E/P): ");
	scanf("%c",&health);
	
	fflush(stdin);
	printf("Enter the residence city/village (C/V): ");
	scanf("%c",&residence);
	
	printf("Enter the age: ");
	scanf("%d",&age);
	
	//make all inputs in lowercase
	//tolower function is already defined in ctype.h
	gen = tolower(gen);
	health = tolower(health);
	residence = tolower(residence);
	
	if(health == 'e' && gen == 'm' && residence == 'c' && (age >= 25 && age <=35)) {
		printf("Eligible for insured\n");
		printf("Maximum policy amount: Rs. 2 Lakhs\n");
		printf("Premium: Rs. 4/1000");
	} else if(health == 'e' && gen == 'f' && residence == 'c' && (age >= 25 && age <=35)) {
		printf("Eligible for insured\n");
		printf("Maximum policy amount: Rs. 1 Lakh\n");
		printf("Premium: Rs. 3/1000");
	} else if(health == 'p' && gen == 'm' && residence == 'v' && (age >= 25 && age <=35)) {
		printf("Eligible for insured\n");
		printf("Maximum policy amount: Rs. 10000\n");
		printf("Premium: Rs. 6/1000");
	}else {
		printf("Person is not insured");
	}
	
}

Sample Output:

Enter the gender male/female (M/F): m
Enter the health excellent/poor(E/P): e
Enter the residence city/village (C/V): c
Enter the age: 32
Eligible for insured
Maximum policy amount: Rs. 2 Lakhs
Premium: Rs. 4/1000

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

Calculate the library penalty charges

Calculate grade of a student