Blogger templates

Searching...
Tuesday, March 26, 2013

Solution of Equations

12:59 AM
This C program will help you to solve two equations and finally will provide you the result of the variables which are used in those equations. Let's see the interesting source codes.You may download all the files related to this program. Click here to download directly from my PC through dropbox.


#include <stdio.h>
int main()
{
    double a1, a2, b1, b2, c1, c2, u, x, y;
    menu:
    system("cls");
    printf("Two equations are:\n \na1x + b1y = c1... ... ... (1) \na2x + b2y = c2... ... ... (2)");
    printf("\n \nEnter the co-efficient of the variables: \n \n");
    printf("a1 = ");
    scanf("%lf", &a1);
    printf("b1 = ");
    scanf("%lf", &b1);
    printf("c1 = ");
    scanf("%lf", &c1);
    printf("a2 = ");
    scanf("%lf", &a2);
    printf("b2 = ");
    scanf("%lf", &b2);
    printf("c2 = ");
    scanf("%lf", &c2);
    u = a1 * b2 - a2 * b1;
    x = (b2 * c1 - b1 * c2) / u;
    y = (a1 * c2 - a2 * c1) / u;
    if ((int) u == 0) {
        printf("\nThe solution of (x,y) isn't executable !\n");
        printf("It's called 'Math Error'.\n");
    }
    else {
        printf("\nx = %0.2lf  and \t", x);
        printf("y = %0.2lf\n\n", y);
        printf("(x, y) = (%0.2lf, %0.2lf)\n", x, y);
    }
    printf("\nPress any key to continue solving equations ");
    getch();
    goto menu;

}

0 comments:

Post a Comment