Write a C program that calculates the stress and strain on an engineering material based onuser input. The program should:Prompt the user to enter the type of material from a list (e.g., "Steel", "Aluminum", "Copper").Depending on the material selected, use predefined values for Young's modulus (E) for eachmaterial (e.g., Steel = 200 GPa, Aluminum = 69 GPa, Copper = 110 GPa).Ask the user to input the force applied (in Newtons) and the cross-sectional area of the material(in square meters).Calculate the stress using the formula: Stress (σ) = Force (F) / Area (A).Ask the user to input the original length of the material (in meters) and the amount it elongated(in meters).Calculate the strain using the formula: Strain (ε) = Elongation (ΔL) / Original Length (L0).Finally, calculate and display the stress and strain on the material.Additional Notes:Make sure to use floating-point variables for accuracy.Provide clear instructions and outputs so the user can easily follow along.Include error checking for invalid inputs (e.g., negative values)
Question
Write a C program that calculates the stress and strain on an engineering material based onuser input. The program should:Prompt the user to enter the type of material from a list (e.g., "Steel", "Aluminum", "Copper").Depending on the material selected, use predefined values for Young's modulus (E) for eachmaterial (e.g., Steel = 200 GPa, Aluminum = 69 GPa, Copper = 110 GPa).Ask the user to input the force applied (in Newtons) and the cross-sectional area of the material(in square meters).Calculate the stress using the formula: Stress (σ) = Force (F) / Area (A).Ask the user to input the original length of the material (in meters) and the amount it elongated(in meters).Calculate the strain using the formula: Strain (ε) = Elongation (ΔL) / Original Length (L0).Finally, calculate and display the stress and strain on the material.Additional Notes:Make sure to use floating-point variables for accuracy.Provide clear instructions and outputs so the user can easily follow along.Include error checking for invalid inputs (e.g., negative values)
Solution
Here is a simple C program that follows the instructions you provided:
#include <stdio.h>
int main() {
float force, area, length, elongation;
float stress, strain;
int material;
float E;
printf("Select the type of material:\n1. Steel\n2. Aluminum\n3. Copper\n");
scanf("%d", &material);
if(material == 1) {
E = 200;
} else if(material == 2) {
E = 69;
} else if(material == 3) {
E = 110;
} else {
printf("Invalid material selection.\n");
return 0;
}
printf("Enter the force applied (in Newtons): ");
scanf("%f", &force);
printf("Enter the cross-sectional area of the material (in square meters): ");
scanf("%f", &area);
if(force < 0 || area < 0) {
printf("Invalid input. Force and area should be positive values.\n");
return 0;
}
stress = force / area;
printf("Enter the original length of the material (in meters): ");
scanf("%f", &length);
printf("Enter the amount the material elongated (in meters): ");
scanf("%f", &elongation);
if(length < 0 || elongation < 0) {
printf("Invalid input. Length and elongation should be positive values.\n");
return 0;
}
strain = elongation / length;
printf("The stress on the material is: %.2f GPa\n", stress);
printf("The strain on the material is: %.2f\n", strain);
return 0;
}
This program first asks the user to select the type of material. Depending on the selection, it assigns a predefined value to Young's modulus (E). It then asks the user to input the force applied and the cross-sectional area of the material. It calculates the stress using the formula provided. It then asks the user to input the original length of the material and the amount it elongated. It calculates the strain using the formula provided. Finally, it displays the stress and strain on the material. It also includes error checking for invalid inputs.
Similar Questions
A material has a length of 5 meters, a cross-sectional area of 0.003 m², and a Young's modulus of 4 x 10^10 N/m². If it experiences a stress of 2 x 10^7 N/m², what is the strain?
. Figure shows the strain-stress curve for a givenmaterial. What are (i) Young's modulus and (ii)approximate yield strength for this material
how to determine the stress block parameters for a RCC element when the stress strain graph is given
Strain is...Group of answer choicesthe deformation of a material under stressfailure of a material under stressa material's internal resistance to applied forcesthe force applied to a material
A material is stretched by a force of 6000 N, resulting in a stress of 3 x 10^7 N/m². If the material has a cross-sectional area of 0.01 m², what is its strain?
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.