Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //система линейных уравнений с 2мя переменными
- #include <stdio.h>
- void displayMessage();
- int hasSolution(double a, double b, double d, double e);
- double getX(double a, double b, double c, double d, double e, double f);
- double getY(double a, double b, double c, double d, double e, double f);
- void displaySolutions(double x, double y);
- int menu();
- int main() {
- double a, b, c, d, e, f;
- double x, y;
- int choice;
- displayMessage();
- do
- {
- do
- {
- menu();
- scanf( "%d", &choice );
- } while (choice < 1 || choice > 3);
- switch (choice)
- {
- case 1:
- printf( "Enter a, b, and c: " );
- scanf( "%lf", &a );
- scanf( "%lf", &b );
- scanf( "%lf", &c );
- printf( "Enter d, e, and f: " );
- scanf( "%lf", &d );
- scanf( "%lf", &e );
- scanf( "%lf", &f );
- break;
- case 2:
- if (hasSolution(a, b, d, e))
- {
- x = getX(a, b, c, d, e, f);
- y = getY(a, b, c, d, e, f);
- displaySolutions(x,y);
- }
- else
- {
- printf( "The system has no solution\n" );
- }
- break;
- case 3:
- printf( "Thanks for using my program\n" );
- }
- } while (choice != 3);
- return 0;
- }
- void displayMessage(){
- printf( "This program calculates solutions to systems of linear equations of the form\n\n");
- printf( " aX + bY = c\n" );
- printf( " dX + eY = f\n\n" );
- return;
- }
- int hasSolution(double a, double b, double d, double e){
- int s;
- s=(a*e - d*b != 0);
- return s;
- }
- double getX(double a, double b, double c, double d, double e, double f){
- double x;
- x=(c * e - f * b) / (a * e - d * b);
- return x;
- }
- double getY(double a, double b, double c, double d, double e, double f){
- double y;
- y=(a * f - d * c) / (a * e - d * b);
- return y;
- }
- void displaySolutions(double x, double y)
- {
- printf ("The solution is (%lf, %lf)\n", x, y );
- return;
- }
- int menu()
- {
- printf( "\nEnter 1 to enter a new system\n" );
- printf( " 2 to find the solution of the system\n" );
- printf( " 3 to exit\n" );
- printf( "Choice: " );
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement