Advertisement
Gguidini

Código IV

Mar 22nd, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.78 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. /* Function using reference to return 2 values
  5.     Values x0 and x1 are parameters. Others are values.*/
  6. int bask(double a, double b, double c, double* x0, double* x1){
  7.     /* Returns -1 if delta <0*/
  8.     double delta = b*b - 4*a*c;
  9.     if(delta < 0){
  10.         return -1;
  11.     }
  12.     /* Values go to x0 and x1 */
  13.     *x0 = (delta-b)/2*a;
  14.     *x1 = (delta+b)/2*a;
  15.     /* Function has roots */
  16.     return 1;
  17. }
  18.  
  19. int main(){
  20.     printf("Inform a, b and c\n");
  21.     double a, b, c, x0, x1;
  22.     scanf("%lf %lf %lf", &a, &b, &c);
  23.     /* x0 and x1 passed by reference*/
  24.     int r = bask(a, b, c, &x0, &x1);
  25.     if(r == 1)
  26.         printf("Solution: x0 = %lf, x1= %lf\n", x0, x1);
  27.     else
  28.         printf("Equation has no real solutions\n");
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement