luc021.c (2507B)
1 /* A certain grade of steel is graded according to the following conditions: 2 (i) Hardness must be greater than 50 3 (ii) Carbon content must be less than 0.7 4 (iii) Tensile strength must be greater than 5600 5 6 The grades are as follows: 7 Grade is 10 if all three conditions are met 8 Grade is 9 if conditions (i) and (ii) are met 9 Grade is 8 if conditions (ii) and (iii) are met 10 Grade is 7 if conditions (i) and (iii) are met 11 Grade is 6 if only one condition is met 12 Grade is 5 if none of the conditions are met 13 14 Write a program, which will require the user to give values of hardness, 15 carbon content and tensile strength of the steel under consideration and output 16 the grade of the steel. */ 17 18 /* Let Us C, Chap- 4, Page - 71, Qn No.: D(c) */ 19 20 #include <stdio.h> 21 int main() 22 { 23 double hardness, carbon_content, tensile_strength; 24 printf("Enter the details of the steel below - \n"); 25 printf("1. Hardness : "); 26 scanf("%lf", &hardness); 27 printf("2. Carbon Content : "); 28 scanf("%lf", &carbon_content); 29 printf("3. Tensile Strength : "); 30 scanf("%lf", &tensile_strength); 31 32 // storing how many conditions are met as boolean result 33 int condition_met, condition1, condition2, condition3; 34 condition1 = hardness > 50; 35 condition2 = carbon_content < 0.7; 36 condition3 = tensile_strength > 5600; 37 condition_met = condition1 + condition2 + condition3; 38 39 // now grading according the result 40 int grade; 41 if (condition_met == 3) 42 grade = 10; 43 else if (condition_met == 2) 44 { 45 if (condition1 && condition2) 46 grade = 9; 47 else if (condition2 && condition3) 48 grade = 8; 49 else if (condition1 && condition3) 50 grade = 7; 51 } 52 else if (condition_met == 1) 53 grade = 6; 54 else 55 grade = 5; 56 57 // printing the result 58 printf("\n------------- Result -------------"); 59 printf("\n1. Hardness : Condition %s", condition1 ? "MET" : "DID NOT MET"); 60 printf("\n2. Carbon Content : Condition %s", condition2 ? "MET" : "DID NOT MET"); 61 printf("\n3. Tensile Strength : Condition %s", condition3 ? "MET" : "DID NOT MET"); 62 printf("\nTotal Condition Met : %d", condition_met); 63 printf("\n\nGrade : %d\n\n", grade); 64 return 0; 65 } 66 67 /* I did not used this long variable names. I used very short just the first letter of the word. 68 After writting the whole program, I just renamed the valiables. This is possible in Visual Stdio Code. */