Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- /* Function using reference to return 2 values
- Values x0 and x1 are parameters. Others are values.*/
- int bask(double a, double b, double c, double* x0, double* x1){
- /* Returns -1 if delta <0*/
- double delta = b*b - 4*a*c;
- if(delta < 0){
- return -1;
- }
- /* Values go to x0 and x1 */
- *x0 = (delta-b)/2*a;
- *x1 = (delta+b)/2*a;
- /* Function has roots */
- return 1;
- }
- int main(){
- printf("Inform a, b and c\n");
- double a, b, c, x0, x1;
- scanf("%lf %lf %lf", &a, &b, &c);
- /* x0 and x1 passed by reference*/
- int r = bask(a, b, c, &x0, &x1);
- if(r == 1)
- printf("Solution: x0 = %lf, x1= %lf\n", x0, x1);
- else
- printf("Equation has no real solutions\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement