write a C code program THAT USES ARRAYS to calculate the shear and moment at eve
ID: 3765571 • Letter: W
Question
write a C code program THAT USES ARRAYS to calculate the shear and moment at every foot on a 20-foot long uniformly loaded beam. Produce an output table as shown below. Include a decision structure in the loop structure to print a message if the maximum moment (m_max) is higher than the maximum allowable moment (m_allow) and print a message indicating this. Inside the loop, include a decision structure to determine the maximum moment (mmax) along with the distance (x) at which this maximum moment occurs on the beam. Indicate the value of the maximum moment (mmax) and where it is located (x). Outside the loop, include a decision structure to determine if the beam is safe and print a message indicating safe or unsafe.
Input data: Output data:
x[L+1] - distance array
w - load (user input) v[L+1] - shear array
L - length (define as 20) m[L+1] - moment array
M_ALLOW(define as 1500) m_max - maximum moment
distance - value of x at m_max
Equations:
v = w L/2 - w x
m = w L x / 2 - w x2 / 2
OUTPUT SHOULD APPEAR AS FOLLOWS:
Enter the uniformly distributed weight in lb./ft.>>40
Weight is 40.00 lb/ft. Length is 20.00 ft.
DISTANCE SHEAR MOMENT
(x ~ ft.) (V ~ lbs.) (M ~ ft-lb)
____________________________________________________
0 400 0
1 360 380
2 320 720
...
9 40 1980
10 0 2000
11 -40 1980
...
19 -360 380
20 -400 0
Beam is unsafe, allowable moment is 1500 ft-lb.
Maximum moment 2000 ft-lb is at x = 10 ft.
Explanation / Answer
Here is the code for you. If you have any further queries, just get back to me.
#include <stdio.h>
int main()
{
int weight, length = 20, i, M_ALLOW = 1500, m_max = 0, x = 0;
int shear, moment;
printf("Enter the uniformly distributed weight in lb./ft.>> "); //Reads the weight.
scanf("%i", & weight);
printf("Weight is %.2f lb/ft. Length is %.2f ft. ", (float)weight, (float)length); //Prints the header.
printf("DISTANCE SHEAR MOMENT ");
printf("(x ~ ft.) (V ~ lbs.) (M ~ ft-lb) ");
printf("____________________________________________________ ");
for(i = 0; i <= 20; i++) //Calculates the shear and moment for every value of i.
{
shear = weight*(length / 2 - i);
moment = weight*i/2 *(length - i);
printf("%i %i %i ", i, shear, moment);
if(moment > m_max) //If moment is greater than maximum allowable moment.
{
m_max = moment; //Update the m_max.
x = i; //And the point at which m_max is updated.
}
}
if(m_max > M_ALLOW) //If m_max is greater than maximum allowable moment, print relavent message.
printf("Beam is unsafe, allowable moment is 1500 ft-lb. ");
else
printf("Beam is safe, maximum moment is %i ft-lb. ", m_max);
printf("Maximum moment %i ft-lb is at x = %i ft. ", m_max, x);
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.