Question: In my code where would I put to write to an output file and how would I do it? Ive got it reading from one

In my code where would I put to write to an output file and how would I do it? Ive got it reading from one I just need to write to another?

#include #include

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); }

/* Main function */ int main() { int n, i, j, temp;

double base, length, e, load, a, deflection;

FILE *fp = fopen("C:\\Users\\frede\\Desktop\\beam.txt", "r");

if(!fp){

printf("can not read from beam.txt ");

return 0;

}

fscanf(fp, "%d", &n);

printf("****************************************************** ");

printf("\t\tBEAM DEFLECTION ");

for(i = 0; i < n; ++i) {

fscanf(fp, "%lf %lf %lf %lf", &length, &base, &e, &load);

printf("BEAM NO. %d\tTotal length = %.2lf m ", i + 1, length);

printf("\t\t2%% of length = %.2lf m ", length * 0.02);

printf("\tDISTANCE FROM FIXED END\t\tDEFLECTION ");

a = 1;

temp = 0;

while(a <= length) {

deflection = calculate_deflection(load, a, e, base, length);

printf("\t\t%.2lf\t\t\t%.2lf ", a, deflection);

a += 1;

if(deflection >= (0.02 * length)) {

temp = 1;

break;

}

}

if(!temp) {

printf("\tDeflection of 2%% of length not reached ");

}

printf(" ");

}

printf("****************************************************** ");

fclose(fp);

return 0;

}

#include #include

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); }

/* Main function */ int main() { int n, i, j, temp;

double base, length, e, load, a, deflection;

FILE *fp = fopen("C:\\Users\\frede\\Desktop\\beam.txt", "r");

if(!fp){

printf("can not read from beam.txt ");

return 0;

}

fscanf(fp, "%d", &n);

printf("****************************************************** ");

printf("\t\tBEAM DEFLECTION ");

for(i = 0; i < n; ++i) {

fscanf(fp, "%lf %lf %lf %lf", &length, &base, &e, &load);

printf("BEAM NO. %d\tTotal length = %.2lf m ", i + 1, length);

printf("\t\t2%% of length = %.2lf m ", length * 0.02);

printf("\tDISTANCE FROM FIXED END\t\tDEFLECTION ");

a = 1;

temp = 0;

while(a <= length) {

deflection = calculate_deflection(load, a, e, base, length);

printf("\t\t%.2lf\t\t\t%.2lf ", a, deflection);

a += 1;

if(deflection >= (0.02 * length)) {

temp = 1;

break;

}

}

if(!temp) {

printf("\tDeflection of 2%% of length not reached ");

}

printf(" ");

}

printf("****************************************************** ");

fclose(fp);

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!