Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- int quadEq(double a, double b, double c, double* x1, double* x2){
- double d = (b * b) - 4 * a * c;
- if(d > 0){
- *x1 = (-b - sqrt(d)) / 2 * a;
- *x2 = (-b + sqrt(d)) / 2 * a;
- }else if(d == 0){
- *x1 = -b / 2 * a;
- *x2 = *x1;
- }else{
- return -1;
- }
- return 0;
- }
- int main(int argc, char *argv[]){
- if(argc != 4){
- fprintf(stderr, "Invalid arguments!\n");
- return 1;
- }
- double a = atof(argv[1]);
- double b = atof(argv[2]);
- double c = atof(argv[3]);
- double x1,x2;
- if(quadEq(a,b,c,&x1,&x2) == 0){
- printf("x1 = %.2lf , x2 = %.2lf\n", x1,x2);
- }else{
- printf("No real roots");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment