Saturday, 9 January 2016

Bhaskara's Formula (Algorithm 2.2)


Before seeing the solution make sure that you tried enough. Don’t paste the whole code, just find out the logic. If you stuck in trouble, just inform me on comment.

/**Bismillahir Rahmanir Rahim.**/

#include <stdio.h>
#include <math.h>
int main()
{
    double A, B, C, X1, X2, D;
    printf("Please, Input A, B and C.\n");
    scanf("%lf %lf %lf", &A, &B, &C);
    D = (B*B) - (4*A*C);
    if(D<0)
        printf("There is no Solution\n");
    else if(D==0)
    {
        X1 = (-B/(2*A));
        printf("X = %.2lf\n", X1);
    }
    else
    {
        X1 = (-B + sqrt(D))/(2*A);
        X2 = (-B - sqrt(D))/(2*A);
        printf("X1 = %.2lf\n", X1);
        printf("X2 = %.2lf\n", X2);
    }
    return 0;
}

0 comments:

Post a Comment

Note: only a member of this blog may post a comment.