URI|1036 Bhaskara’s Formula solution

  • by
uri 1024 Encryption solution

Well, the problem says it all. You need to calculate the root of Bhaskara,s Formula.

Don’t know Bhaskara’s Formula? It is actually Algebra’s Quadratic Formula.

The Quadratic/ Bhaskaras formula is : ax2 + bx + c .

And Quadratic Formula’s root is :

So, That’s it. We have to just print the positive and negative value of the quadratic formula.

#include<sdtio.h>
#include<math.h>
int main(){
 double a,b,c;
 scanf("%lf %lf %lf",&a,&b,&c);
 if(a> 0 && (pow(b,2)-(4*a*c))>0){
   double r1 = (-b + sqrt(pow(b,2) - (4*a*c)) ) / (2*a);
   double r2 =  (-b - sqrt(pow(b,2) - (4*a*c)) ) / (2*a);
   printf("R1 = %.5lf\nR2 = %.5lf\n",r1,r2);
 }else{
   printf("Impossivel calcular\n");
 } 
 return 0;
 } 

Click to rate this post!
[Total: 1 Average: 5]
Tags: