English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

source code for a program that computes for the roots of a quadratic equation, without using factoring method and quadratic formula

2007-01-26 10:20:15 · 1 answers · asked by Sammy Baby 1 in Computers & Internet Programming & Design

1 answers

Try something like this:

#include
#include

int main()
{
// declare variables

double radicand, x1, x2, a, b, c;

// get coefficents

printf("Enter a non-zero value for a:\n");
scanf("%lf", &a);

printf("Enter the value for b:\n");
scanf("%lf", &b);

printf("Enter the value for c:\n");
scanf("%lf", &c);

// compute radicand and roots

radicand = b * b - 4 * a * c

if (radicand < 0)
printf("Your equation produeced complex zeroes.\n")
else
{
x1 = (-b + sqrt(radicand)) / (2 * a);
x2 = (-b - sqrt(radicand)) / (2 * a);

printf "x1 = %lf\n", x1);
printf "x2 = %lf\n", x2);
}


You may need to add error checks or contingencies for complex rotos as well, but this should give you the general idea. When compiling you may need at add the -lm switch.

2007-01-26 11:24:14 · answer #1 · answered by Runa 7 · 0 0

fedest.com, questions and answers