C Program to Count Persons with Height > 170 and Weight < 50 from 5 Inputs

Introduction

When handling structured data like height and weight, C programs can help filter based on conditions. This blog explains how to write a C program to read height and weight of 5 persons and count how many have height greater than 170 and weight less than 50. This kind of task is common in basic data analysis or eligibility checks.


Problem Description

The task is to accept height and weight inputs of five individuals, and then count and display how many meet the following criteria:

  • Height > 170
  • Weight < 50

C Program to Solve the Problem

#include <stdio.h>

int main() {
float height, weight;
int count = 0;

for (int i = 1; i <= 5; i++) {
printf("Enter height (in cm) and weight (in kg) for person %d: ", i);
scanf("%f %f", &height, &weight);

if (height > 170 && weight < 50) {
count++;
}
}

printf("Number of persons with height > 170 and weight < 50: %d\n", count);

return 0;
}

How the Code Works

  • Loop: Runs 5 times for 5 individuals.
  • Input: Each loop asks for height and weight.
  • Condition Check: if (height > 170 && weight < 50) evaluates both conditions.
  • Counter: Increments only if both conditions are met.

Sample Output

Enter height (in cm) and weight (in kg) for person 1: 172 48  
Enter height (in cm) and weight (in kg) for person 2: 165 52
...
Number of persons with height > 170 and weight < 50: 2

Use Case

This program is useful in scenarios where you want to filter a population based on physical criteria such as in recruitment, health checks, or fitness tracking.

Conclusion

This C program to count persons with height greater than 170 and weight less than 50 helps you understand how to use if conditions in loops to filter data. It’s a great exercise in conditional logic and real-world filtering.

Previous Article

C Program to Calculate Total and Average Marks of 5 Students in 3 Subjects Using Nested Loops

Next Article

C Program to Check Whether a Number is Prime or Not

Write a Comment

Leave a Comment

Your email address will not be published. Required fields are marked *

Subscribe to our Newsletter

Subscribe to our email newsletter to get the latest posts delivered right to your email.
Pure inspiration, zero spam ✨