Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
C++ Exercise - 2 - Binomial ( Codes )
#1
Code:
#include <iostream>
#include <cmath>


using namespace std;

int main()
{
   double a , b , c, d, x1, x2;
   cout << "ax^2 + bx + c\n\n";
   cout << "Enter a : ";
   cin >> a;
   cout << "Enter b : ";
   cin >> b;
   cout << "Enter c : ";
   cin >> c;
   d = (b*b) - (4*a*c);
   d = sqrtf(d);
   if(d<0){
       cout << "There is no root\n";
   }else if (d>0){
       x1 = (- b + d) / (2*a);
       x2 = (- b - d) / (2*a);
       cout << "\n\nX1 : " << x1 << "\nX2 : " << x2 << endl;
   }else{
       x1 = -b / (2*a);
       cout << "There is only one x : " << x1 << endl;
   }
   return 0;
}


Attached Files
.pdf   Binomial.pdf (Size: 405.01 KB / Downloads: 0)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)