我想讓程序解決我的方程,但很遺憾它沒有。另外,我想讓它打印一個答案,這取決於我在方程中輸入的x的值。請讓我知道我將如何打印答案或如何編程,以便方程式給出我可以打印的答案。如何在C中打印方程的答案?
/* Preprocessor directives */
#include <stdio.h>
#include <math.h>
/* Main program */
void main()
{
/*
variable declaration section comments
l: length value
q: value of q
ei: value of ei
s: l devided by 2 since 0 < x < l/2
b: the length l (thus, 20)
z: 0
first_equation: The first equation pertaining to 0 < x < l/2
second_equation:The second equation pertaining to l/2 < x < l
*/
double x, first_equation, second_equation, l, q, ei, s, b, z;
l = 20.0;
q = 4000.0;
ei = 1.2 * (pow(10.0, 8.0));
s = l/2.0;
b = l;
z = 0.0;
printf ("please enter the x-value\n");
scanf ("%lf", &x);
/* Deflection equations */
first_equation = ((q * x)/(384.0 * ei)) * ((9 * (pow(l, 3.0))) - (24.0 * l * (pow(x, 2.0))) + (16 * (pow(x, 3.0))));
second_equation = ((q * l)/(384.0 * ei)) * ((8 * (pow(x, 3.0))) - (24.0 * l * (pow(x, 2.0))) + (17 * (pow(l, 2.0)) * x) - (pow(l, 3.0)));
/* Determining what equation to use */
if (x >= z && x <= s)
printf ("\n first_equation\n\n");
else if (x > s && x <= b)
printf ("\n second_equation\n\n", second_equation);
else if (x < 0 || x > b)
printf ("\n invalid location\n\n");
return;
}
正因爲如此,這個問題只給出一半的數據。等式的數學表達式是什麼?而最重要的是,是什麼讓你認爲「方程式不解決」 - 什麼不符合你的期望?請明確點。 – iksemyonov
這是「C」還是「C++」? – Galik
所以基本上我會想給first_equation和second_equation給出值的答案和任何x要打印,或者至少使它爲我解決它,然後我會讓它與正確的值相對應。 – DanielRossi