I am currently working on a program (C++) to calculate the quadratic formula. (I program as a hobby) I looked at some of the algorithms online, but only starting Geometry, I had no clue what anything meant. Could someone please explain one of the algorithms in language a freshman could understand, preferably an algorithm that requires less calculations if it were to be programmed
__________________
maple walnut fudge recipes ~ oat meal cookies recipe ~ quick and easy recipes
preferably an algorithm that requires less
Moderator: Board moderators
-
- New poster
- Posts: 1
- Joined: Wed Mar 05, 2014 8:21 am
preferably an algorithm that requires less
Last edited by merkutinaa on Fri Mar 14, 2014 9:29 am, edited 2 times in total.
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: preferably an algorithm that requires less
http://en.wikipedia.org/wiki/Quadratic_formula
Code: Select all
#include <iostream>
#include <cmath>
using namespace std;
int main() {
double a, b, c;
while(cin >> a >> b >> c)
cout << "x = " << (-b + sqrt(b * b - 4.0 * a * c)) / (2.0 * a) << " and " << (-b - sqrt(b * b - 4.0 * a * c)) / (2.0 * a) << endl;
return 0;
}
Check input and AC output for thousands of problems on uDebug!