preferably an algorithm that requires less

Let's talk about algorithms!

Moderator: Board moderators

Post Reply
merkutinaa
New poster
Posts: 1
Joined: Wed Mar 05, 2014 8:21 am

preferably an algorithm that requires less

Post by merkutinaa » Thu Mar 13, 2014 12:28 pm

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
Last edited by merkutinaa on Fri Mar 14, 2014 9:29 am, edited 2 times in total.

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: preferably an algorithm that requires less

Post by brianfry713 » Thu Mar 13, 2014 8:44 pm

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!

Post Reply

Return to “Algorithms”