Problem 23

author
By Supreme2023-03-15
Problem Statement :
Read five persons height and weight and count the number of person having height greater than 170 and weight less than 50,
Code:

#include <stdio.h>

int main(){

//23. Read five persons height and weight and count the number of //person having height greater than 170 and weight less than 50,


printf("\tNumber Of Person Having Height Greater Than 170 And Weight Less Than 50");
printf("\n====================================================================================");
int height,weight,i,n=0;

for (i=0;i<5;i++){
printf("\n\nEnter The Height Of Person [%d] : ",i+1);
scanf("%d",&height);

printf("\nEnter The Weight Of Person [%d] : ",i+1);
scanf("%d",&weight);

printf("____________________________________________");

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

printf("\n\n______________________________________________________________________________");
printf("\n\n%d Person Having Height Greater Than 170 And Weight Less Than 50",n);
printf("\n\n______________________________________________________________________________\n\n");
return 0;
}

Description :
  • The program reads the height and weight of five persons and counts the number of persons who have a height greater than 170 and weight less than 50.
  • The variables used in the program are 'height' and 'weight' for reading the values of height and weight respectively, 'i' for the loop counter and 'n' for storing the count of persons who meet the given criteria.
  • The loop runs for five times to read the height and weight of each person.
  • Inside the loop, the program checks if the height is greater than 170 and weight is less than 50. If the condition is true, the value of 'n' is incremented.
  • After the loop, the program displays the count of persons who meet the given criteria.
  • Finally, the program ends by returning 0.
Output Image:
Output-image

© Copyright 2022. All right reserved, GTU Coder.