Thursday 25 July 2013

Chapter 2 solutions Problem[F][d]

Question-A certain grade of steel is graded according to the following conditions:
(i) Hardness must be greater than 50
(ii) Carbon content must be less than 0.7
(iii) 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 the conditions are met
Write a program, which will require the user to give values of hardness, carbon content and tensile strength of the steel under consideration and output the grade of the steel.
Solution-
Here is the solution.

#include<stdio.h>

int main()
{
int hard,ts;
float cc;
printf("Enter the Hardness, Tensile strength and carbon content of the steel\n");
scanf("%d%d%f",&hard,&ts,&cc);
if(hard>50&&cc<0.7&&ts>5600)
printf(" Grade 10\n");
else if(hard>50&&cc<0.7&&!(ts>5600))
printf("Grade 9\n");
else if(!(hard>50)&&cc<0.7&&ts>5600)
printf("Grade 8\n");
else if(hard>50&&!(cc<0.7)&&ts>5600)
printf(" Grade 7\n");
else if(hard>50||cc<0.7||ts>5600)
printf("Grade 6\n");
else 
printf("Grade 5\n");
return 0;
}

5 comments: