#computer-science
Вопрос:
Когда я запускаю этот код, он извлекает странный символ, где должен быть ответ на математическую часть. Я попробовал значения a=1 b=4 c=40, и это не дает правильного ответа. Может кто-нибудь сказать мне, что я делаю не так? Я дважды проверил математику и почти уверен, что математическая часть в порядке.
//Project by Abigail Alvarado
//Question 1
#include <stdio.h>
#include <math.h>
int main()
{
//declaring variables
float a, b, c; //These will be used in the quadratic equation that will give us lambda 1 and 2
float d, root1, root2; //d is the quadratic equation determinant.
float real, img;
float y, theta;
int t;
t = 0;
d = (b * b) - (4*a*c);
/*D=d/dt or lambda; (y(0) and y'(0); ax^2 bx c = 0 */
//Asking for user input of coefficients
printf("Enter the values for a, b, and c separated by a space: ");
scanf("%f %f %f", amp;a, amp;b, amp;c);
if(d < 0) //if d is less than 0; the roots are complex and different.
{
real = (-b/(2*a));
img = sqrt(-d)/(2*a);
printf("Roots are complex conjugates.n");
printf("Roots of quadratic equation are: n Root1 = %.3f %.3fi n Root2 = %.3f-%.3fi", real, img, real, img);
}
else if(d==0) //if d==0; the roots are real and equal.
{
root1 = root2 = real;
printf("Roots are repeating real numbers.n");
printf("Roots of the quadratic equation are: n %.3f n %.3%f", root1, root2);
}
else if(d > 0) //if d is greater than 0; the roots are real and different.
{
real = (-b/(2*a));
root1 = real (sqrt(d)/(2*a));
root2 = real - (sqrt(d)/(2*a));
printf("Roots are non-repeating real numbers.n");
printf("Roots of quadratic equation are: nRoot 1: %.3f nRoot 2: %.3f ", root1, root2);
}
//Asking user input of initial conditions; y(0)=? y'(0)=?
float i1, i2; //initial conditions
printf("nEnter two initial conditions separated by a space (y(0) and y'(0)): ");
scanf("%f %f", amp;i1, amp;i2);
//using initial conditions to find C and theta
//Since t is equal to 0; e raised to (zero * any number) is equal to 1.
printf("nUsing the first initial condition, C is equal to %.3f / (%.3f * theta). ", i1, (cos(img)));
printf("nUsing the second initial condition, C is equal to %.3f / (%.3f * theta). ", i2, (cos(img)));
return (0);
}