-
Language
C
-
Description
Quadratic equation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main (void)
{
float a, b, c, discriminant, x1;
float x2;
printf ("Enter the value of a: ");
scanf ("%f", &a);
(void) getchar ();
printf ("Enter the value of b: ");
scanf ("%f", &b);
(void) getchar ();
printf ("Enter the value of c: ");
scanf ("%f", &c);
(void) getchar ();
discriminant=b*b-4.0*a*c;
if(discriminant<0)
{
discriminant=-discriminant;
printf ("Imaginary roots\n");
}
else
printf ("Real roots\n");
if(a!=0)
{
x1=(-b+sqrt(discriminant))/2.0/a;
x2=(-b-sqrt(discriminant))/2.0/a;
}
else
{
x1=0;
x2=0;
printf ("It is not a quadratic equation\n");
}
printf ("Value of discriminant: %g\n", discriminant);
printf ("Value of x1: %g\n", x1);
printf ("Value of x2: %g\n", x2);
putchar ('\n');
system ("pause");
return EXIT_SUCCESS;
}
#include <stdlib.h>
#include <math.h>
int main (void)
{
float a, b, c, discriminant, x1;
float x2;
printf ("Enter the value of a: ");
scanf ("%f", &a);
(void) getchar ();
printf ("Enter the value of b: ");
scanf ("%f", &b);
(void) getchar ();
printf ("Enter the value of c: ");
scanf ("%f", &c);
(void) getchar ();
discriminant=b*b-4.0*a*c;
if(discriminant<0)
{
discriminant=-discriminant;
printf ("Imaginary roots\n");
}
else
printf ("Real roots\n");
if(a!=0)
{
x1=(-b+sqrt(discriminant))/2.0/a;
x2=(-b-sqrt(discriminant))/2.0/a;
}
else
{
x1=0;
x2=0;
printf ("It is not a quadratic equation\n");
}
printf ("Value of discriminant: %g\n", discriminant);
printf ("Value of x1: %g\n", x1);
printf ("Value of x2: %g\n", x2);
putchar ('\n');
system ("pause");
return EXIT_SUCCESS;
}