Digital-Systems-Assignments/Assignment 6/abc.c

33 lines
816 B
C
Raw Permalink Normal View History

2019-09-13 08:27:00 +00:00
/*
* Student: S.K. Soekhlal
* Number: 4860632
2019-10-11 20:34:52 +00:00
* Assignment: 3.6
2019-09-13 08:27:00 +00:00
*/
#include<math.h>
2019-10-11 20:34:52 +00:00
double x1real,x2real,ximag;
extern int a,b,c; /*Variables stored in another file*/
static float discriminant(){
return (pow(b,2)-(4*a*c)); /*Calculate Discriminant */
}
void abc(){
float D = discriminant();
if (D>0){ /*Calculate x1real and x2real if D>0*/
x1real = ((-b+sqrt(D))/(2.0*a)); /*Use 2.0 instead of 2 so a float is calculated instead of an int*/
2019-10-11 20:34:52 +00:00
x2real = ((-b-sqrt(D))/(2.0*a));
ximag = 0;
}
else if(D<0){ /*Calculate x1real and ximag if D<0*/
2019-10-11 20:34:52 +00:00
x1real = -b/(2.0*a);
x2real = x1real;
ximag = (sqrt(-D)/(2.0*a));
}
else{ /*Calculate x1real if D=0*/
2019-10-11 20:34:52 +00:00
x1real = -b/(2.0*a);
x2real = x1real;
ximag = 0;
}
2019-09-13 08:27:00 +00:00
}