Created
October 31, 2017 18:26
-
-
Save mehmeteminkartal/56a15f62a2e64be700b1baf64059cd24 to your computer and use it in GitHub Desktop.
Finds the roots for given quadratic equation values
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "findroots.h" | |
void calcroots(int a, int b, int c) { | |
printf("%dx^2 + %dx + %d = 0\n", a, b, c); | |
int delta = pow(b, 2) - (4 * a * c); | |
printf("Δ = %d\n", delta); | |
double sqrtdelta = sqrt((double)(delta)); | |
if (delta < 0) { | |
printf("There are no real roots for this equation!\n"); | |
} else if (delta > 0) { | |
double root1 = ((double)(-b) + sqrtdelta) / (2.0 * (double)a); | |
double root2 = ((double)(-b) - sqrtdelta) / (2.0 * (double)a); | |
printf("Root1: %lf\n", root1); | |
printf("Root2: %lf\n", root2); | |
} else { // delta == 0 | |
double root = (-(double)b) / (2.0 * (double)a); | |
printf("Root: %lf\n", root); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include <stdio.h> | |
#include <stdint.h> | |
#include <stdbool.h> | |
#include <stdlib.h> | |
#include <math.h> | |
/** | |
Finds the roots for given quadratic equation values | |
@param a X^2 value | |
@param b X value | |
@param c constant | |
*/ | |
void calcroots(int, int, int); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment