Reference no: EM13166224
Write a main function, and the following functions to compute the stress and strain oa a steel rod(D) (in inches) and length(L) in inches subject to the compression load(P) of 10,000 to 1,000,000 pounds in increments of 100,000 pounds. The modulus of elasticity (E) for steel is 30 x 10^6.
function to compute the stress formula:
stress f = P/A
where A =?D2/4.0
A function to compute the strain from the formulas:
elongated or shortened length:
? L = fL/E
strain e = ? l/l = f/E
A function to output the stress and strain at different loads of P.
I have everything working right except the elongated or shortened length isn't taken into account.
#include <stdio.h>
#include <math.h>
#include<conio.h>
// computes stress of a steel rod takes load & diameter as parameters
double stress(long load, double d)
{
double A;
A= (3.14*d*d) /4.0;
return
load/A;
}
//computed strain of a steel road takes load & diameter as parameters
double strain(long load,double d)
{
double f;
//calls stress funtion
f=stress(load,d);
//calculates f/E and returns as strain where E=30*10^6.
return
f/(30*pow(10.0,6));
}
//displays calculated stress & strain at each load.
void output(long p,double stra,double stre)
{
printf("%6ld\t%0.4lf\t%.3lf\n",p,stra,stre);
}
int main()
{
double d,strin,stres;
//diameter,strain,stress
long p;
//load
//gets diameter of steel rod from user
printf("Enter diameter D of steel rod: ");
scanf("%lf",&d);
//computes stress and strain of steel rod at each load through 10000 to 1000000 increments of 100000
printf("\nLoad\tstrain\tstress\n\n");
for
(p=10000;p<=1000000;p=p+100000)
{
strin=strain(p,d);
stres=stress(p,d);
output(p,strin,stres);
}
printf("\n");
getch();
}