Advertisement
ProgramoBien

Equation solver

Jan 30th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.54 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4.  
  5. void solve(double a, double b, double c);
  6. void imprimir(double im);
  7.  
  8. int main()
  9. {
  10.     double a,b,c;
  11.     scanf("%lf %lf %lf",&a,&b,&c);
  12.     solve(a,b,c);
  13.     printf("TERMINADO\n");
  14. }
  15.  
  16. void solve(double a, double b, double c){
  17.     double ans=-b/(a*2);       //-b/2a
  18.     double s=(sqrt(b*b-4*a*c)/(a*2));  //sqrt(b^2-4ac)/(2a)
  19.     ans+=s;
  20.     imprimir(ans);
  21.     printf("y ");
  22.     ans-=2*s;
  23.     imprimir(ans);
  24. }
  25.  
  26. void imprimir(double im){
  27.     printf("Resultado: %.3f, ", im);
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement