Write a C program to check whether the blood donor is eligible for blood donation.
The conditions laid down are as under: (Use if-else statement)
a) Age should be above 18 years but not more than 55 years.
b) Weight should be more than 45 Kg.

This is one of the easiest programs, if you know the concept of if-else conditional statement.

Tutorial πŸ“Ί

Watch tutorial and learn how to solve this problem. πŸ˜‰

Steps πŸͺœ

To check if a person is eligible for blood donation or not

  1. Accept 2 integer numbers from the user and store the values in age and wt. Here, wt variable is to store the weight of the user.
  2. Use following expression to test if user is eligible or not: ((age>18 && age<=55) && wt>45), it returns true if the person is eligible and displays the message, “Blood donor is eligible“.
  3. If above condition (expression) returns false then display the message, “Blood donor is not eligible“.

Code πŸ’»

#include<stdio.h>
#include<conio.h>

void main()
{
  int age = 0, wt = 0;
  clrscr();
  printf("Please enter your age: ");
  scanf("%d", &age);
  printf("Please enter your weight: ");
  scanf("%d", &wt);
  if((age>18 && age<=55) && wt>45)
    printf("\nBlood donor is eligible.");
  else
    printf("\nBlood donor is not eligible.");
  getch();
}

Example 😍

Let’s assume, the user enters age and weight as 23 and 49, respectively.

First of all, it will execute the if statement, but there is Logical AND operator in the conditional statement which means the condition will return true only if both expression are evaluated as true.

First, it will check if (age>18 && age<=55) which is true because value in age variable is 23.

Next, the weight is also greater than 45. Thus, it will display the message:

Blood donor is eligible.

Let’s take another example and this time user enters 58 and 70 for age and weight respectively.

First, it will check if the age falls in range or not which is false because it is greater than 55 and it will not check the next expression in the conditional statement.

Further, it will execute the else part and will display the message as follows:

Blood donor is not eligible.

This is how we write C program to find out if the person is eligible or not for blood donation. For more C programs, click here.