Advertisement
Mizuhara_Chizuru

Untitled

Jul 28th, 2021
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.01 KB | None | 0 0
  1. /*Code by Surya a.k.a Sunny*/
  2. /* by https://www.codechef.com/users/spsc */
  3. #include <bits/stdc++.h>
  4. #define lli long long
  5. #define pi 3.14159265358979323846
  6. #define MOD 1000000007
  7. #define foi(n)  for(lli i=0;i<n;i++)
  8. #define foj(n)  for(lli j=0;j<n;j++)
  9. #define test(T) lli T;cin>>T;while(T--)
  10. #define loop(i, a, b) for(int i = (a); i<= (b); i++)
  11. using namespace std;
  12. int main()
  13. {
  14. cout<<"Enter the value of a,b,c ( in format of ax^2 + bx + c = 0)\n";
  15. float a,b,c;
  16. scanf("%f%f%f",&a,&b,&c);
  17. float r1,r2;
  18. r1=r2=-b/(2*a);
  19. if(a==0)
  20.   printf("Enter a Quadratic eqn");
  21. else if(b>=0&&c>=0)
  22.   {
  23.     float D=(b*b)-4*a*c;
  24.     if(D>0)
  25.     {
  26.       r1=(-b+D)/(2*a);
  27.       r2=(-b-D)/(2*a);
  28.       printf(" Root 1 = %.3f & Root 2 = %.3f",r1,r2);
  29.     }
  30.     else if(D==0)
  31.     {
  32.       r1=r2=(-b)/(2*a);
  33.       printf(" Root 1 = %.3f & Root 2 = %.3f",r1,r2);
  34.     }
  35.     else
  36.     {
  37.       printf(" Root 1 = %.3f+(%.3fi) & Root 2 = %.3f-(%.3fi)\n",r1,D/(2*a),r2,D/(2*a));
  38.     }
  39.   }
  40. else
  41.   printf("Enter a valid eqn");
  42. }
  43.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement