bsc

Comprehensive codebase and cou...
Log | Files | Refs | README | LICENSE

luc021.c (2698B)


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