luc021.c ​
Metadata ​
- Author — Amit Dutta
- Last updated — 12 Dec 2025
- License — MIT License (See the LICENSE file for details)
Problem Statement ​
Problem Statement
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.
Source Code ​
Printing the code
To print this file, open it on GitHub and click Raw before printing, or use the Download Raw button above and print directly from that page.
#include <stdio.h>
int main()
{
double hardness, carbon_content, tensile_strength;
printf("Enter the details of the steel below - \n");
printf("1. Hardness : ");
scanf("%lf", &hardness);
printf("2. Carbon Content : ");
scanf("%lf", &carbon_content);
printf("3. Tensile Strength : ");
scanf("%lf", &tensile_strength);
// storing how many conditions are met as boolean result
int condition_met, condition1, condition2, condition3;
condition1 = hardness > 50;
condition2 = carbon_content < 0.7;
condition3 = tensile_strength > 5600;
condition_met = condition1 + condition2 + condition3;
// now grading according the result
int grade;
if (condition_met == 3)
grade = 10;
else if (condition_met == 2)
{
if (condition1 && condition2)
grade = 9;
else if (condition2 && condition3)
grade = 8;
else if (condition1 && condition3)
grade = 7;
}
else if (condition_met == 1)
grade = 6;
else
grade = 5;
// printing the result
printf("\n------------- Result -------------");
printf("\n1. Hardness : Condition %s", condition1 ? "MET" : "DID NOT MET");
printf("\n2. Carbon Content : Condition %s", condition2 ? "MET" : "DID NOT MET");
printf("\n3. Tensile Strength : Condition %s", condition3 ? "MET" : "DID NOT MET");
printf("\nTotal Condition Met : %d", condition_met);
printf("\n\nGrade : %d\n\n", grade);
return 0;
}
/* I did not used this long variable names. I used very short just the first letter of the word.
After writting the whole program, I just renamed the valiables. This is possible in Visual Stdio Code. */2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49