-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWeek_12_1.c
81 lines (58 loc) · 1.21 KB
/
Week_12_1.c
1
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
* main.c
*
* Created on: Apr 18, 2021
* Author: Jeremy
*/
/*
* main.c
*
* Created on: Apr 18, 2021
* Author: Jeremy
*/
#include <stdio.h>
#include <math.h>
//Calculates the Stress
float StressCalc(float load, float dia)
{
float area, stress;
//Calculates area
area = (M_PI * pow(dia, 2)) / 4;
//Calculates stress
stress = load / area;
return stress;
}
//Calculates the Strain
float StrainCalc(float stress, float elasticity)
{
float strain;
//Calculates strain
strain = stress / elasticity;
return strain;
}
//Display function
void display(float stress, float strain, int l)
{
printf("For a compression load of %d pounds the Stress is %f, and the Strain is %f\n", l,
stress, strain);
}
// main function
int main()
{
float diameter, stress, strain;
int l;
const int elasticity = 30 * pow(10, 6);
printf("Enter the diameter: "); fflush(stdout);
scanf("%f", &diameter);
// loop for each calculation
for (l = 10000; l <= 1000000; l += 100000)
{
//Calls StressCalc
stress = StressCalc(l, diameter);
//Calls StrainCalc
strain = StrainCalc(stress, elasticity);
//Calls display
display(stress, strain, l);
}
return 0;
}