Problem Description
A certain grade of steel is graded according to the following conditions.
Hardness must be greater than 50.
Carbon content must be less than 0.7.
Tensile strength must be greater than 5600.
The grades are as follows:
Grade is 10 if all three conditions are met.
Grade is 9 if conditions (i) and (ii) are met.
Grade is 8 if conditions (ii) and (iii) are met.
Grade is 7 if conditions (i) and (iii) are met.
Grade is 6 if only one condition is met.
Grade is 5 if none of three conditions are met.
Write a program, if the user gives values of hardness, carbon content and tensile strength of the steel under consideration and display the grade of the steel.CODING ARENA
#include <stdio.h>
int main()
{
long t=0,i=0,grade=0;
long hs,ts;
float cc;
scanf("%lu",&t);
for(i=0;i<t;i++)
{
scanf("%lu%f%lu",&hs,&cc,&ts);
if(hs>=50&&cc<=0.7&&ts>=5600)
{
grade=10;
}
else if(hs>=50&&cc<=0.7)
{
grade=9;
}
else if(cc<=0&&ts>=5600)
{
grade=8;
}
else if(hs>=50&&ts>=5600)
{
grade=7;
}
else if (hs>=50||cc<=0.7||ts>=5600)
{
grade=6;
}
else
{
grade=5;
}
printf("Grade %lu\n",grade);
}
return 0;
}
Test Case 1
Input (stdin)2 53 0.7 5602 55 0 5499
Expected OutputGrade 10 Grade 9
Test Case 2
Input (stdin)5 49 0.8 5599 55 0.6 5602 45 0 5601 60 0.2 5700 55 0.5 5500
Expected OutputGrade 5 Grade 10 Grade 8 Grade 10 Grade 9
No comments:
Post a Comment