Question
How would I go to printing to screen at the same time as executing all of this at once? double calculate_deflection(double load, double a, double
How would I go to printing to screen at the same time as executing all of this at once?
double calculate_deflection(double load, double a, double e, double base, double length) { double inertia = (base * pow(length, 3)) / 12.0; return (load * pow(a, 2) * (length - (a / 3))) / (2 * e * inertia); }
int main() { int n, i, temp; double base, length, e, load, a, deflection;
FILE *inputFile = fopen("C:\\Users\\frede\\Desktop\\beam.txt", "r"); FILE *outputFile = fopen("C:\\Users\\frede\\Desktop\\deflection.txt", "w");
if (!inputFile) { printf("can not read from beam.txt "); return 0; }
if (!outputFile) { printf("can not write to deflection.txt "); return 0; }
fscanf(inputFile, "%d", &n);
fprintf(outputFile, "************************************************** "); fprintf(outputFile, "\t\tBEAM DEFLECTION ");
for (i = 0; i < n; ++i) { fscanf(inputFile, "%lf %lf %lf %lf", &length, &base, &e, &load);
fprintf(outputFile, "BEAM NO. %d\tTotal length = %.2lf m ", i + 1, length); fprintf(outputFile, "\t\t2%% of length = %.2lf m ", length * 0.02); fprintf(outputFile, "\tDISTANCE FROM FIXED END\t\tDEFLECTION ");
a = 1; temp = 0;
while (a <= length) { deflection = calculate_deflection(load, a, e, base, length);
fprintf(outputFile, "\t\t%.2lf\t\t\t%.2lf ", a, deflection);
a += 1;
if (deflection >= (0.02 * length)) { temp = 1; break; } }
if (!temp) { fprintf(outputFile, "\tDeflection of 2%% of length not reached "); }
fprintf(outputFile, " "); }
fprintf(outputFile, "************************************************** ");
fclose(inputFile); fclose(outputFile);
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started