Thursday, October 8, 2009

Determine Grade of steel

/*A certain grade of steel is graded according to the following conditions:
*1)Hardness must be greater than 50
*2)Carbon content must be less than 0.7
*3)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 condition 1 & 2 are met
*Grade is 8 if condition 2 & 3 are met
*Grade is 7 if condition 1 & 3 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 code :

==========

#include <stdio.h>
int main(void)
{
int hard,ts; // hard = hardness ; ts = tensile strength
float cc; //cc -- Carbon content

printf("\nEnter hardness of steel: ");
scanf("%d",&hard);
printf("\nEnter Carbon content of steel : ");
scanf("%f",&cc);
printf("\nEnter Tensile strenght of steel : ");
scanf("%d",&ts);

if ( (hard > 50) && (cc < 0.7) && (ts > 5600))
printf("Steel is of 10th Grade");
else if ( (hard > 50) && (cc < 0.7))
printf("Steel is of 9th Grade");
else if ( (cc < 0.7) && (ts > 5600 ))
printf("Steel is of 8th Grade");
else if (( hard > 50) && (ts > 5600 ))
printf("Steel is of 7th Grade");
else if ( (hard > 50) || (cc < 0.7) || (ts > 5600))
printf("Steel is of 6th Grade");
else
printf("Steel is of 5th Grade");
return 0;
}

No comments: