Практикум по программированию. Основы. Ветвление. Система уравнений

From AsIsWiki
Jump to: navigation, search

Назад · Задачи · Дальше


Contents

Java

import java.util.Scanner;

public class Task12 {

    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);

        System.out.println();
        System.out.println(" Решение системы уравнений:");
        System.out.println(" A * X + B * Y = C  и  D * X + E * Y = F");
        System.out.println("-----------------------------------------");

        System.out.print(" Введите A B C D E F: ");
        double a = in.nextDouble();
        double b = in.nextDouble();
        double c = in.nextDouble();
        double d = in.nextDouble();
        double e = in.nextDouble();
        double f = in.nextDouble();

        System.out.println("-----------------------------------------");

        if (a / d != b / e) {

            double y = (f * a - d * c) / (e * a - d * b);
            double x = (c - b * y) / a;

            System.out.printf(
                    " Система имеет единственное решение: X = %.2f, Y = %.2f\n", x, y);

        } else if (a / d == c / f) {

            System.out.println(" Система имеет бесконечно много решений");

        } else {

            System.out.println(" Система не имеет решений");

        }
    }
}


C++

// g++ 4.2

#include <iostream>

using namespace std;

int main() {
    
    double a, b, c, d, e, f;
    
    cout << "\n Решение системы уравнений:\n";
    cout << " A * X + B * Y = C  и  D * X + E * Y = F\n";
    cout << "-----------------------------------------\n";
    
    cout << " Введите A B C D E F: ";
    cin >> a >> b >> c >> d >> e >> f;
    
    cout << "-----------------------------------------\n";
    
    if (a / d != b / e) {
        
        double y = (f * a - d * c) / (e * a - d * b);
        double x = (c - b * y) / a;
        
        printf(" Система имеет единственное решение: X = %.2f, Y = %.2f", x, y);
        
    } else if (a / d == c / f) {
            
        cout << " Система имеет бесконечно много решений";
            
    } else {
            
        cout << " Система не имеет решений";
            
    }
    
    cout << "\n\n";
    return 0;
}


Python

# Python 3

print('\n Решение системы уравнений:')
print(' A * X + B * Y = C  и  D * X + E * Y = F')
print('-----------------------------------------')

a, b, c, d, e, f = input(' Введите A B C D E F: ').split()

print('-----------------------------------------')

a = float(a); b = float(b); c = float(c)
d = float(d); e = float(e); f = float(f)

if a / d != b / e:

    y = (f * a - d * c) / (e * a - d * b)
    x = (c - b * y) / a

    print(' Система имеет единственное решение: X = %.2f, Y = %.2f' % (x, y))

elif a / d == c / f:

    print(' Система имеет бесконечно много решений')

else:

    print(' Система не имеет решений')


Pascal



JavaScript

<html lang="ru">
<head>
    <meta charset="UTF-8">
    <script>
        function getNumbers(str) {
            return str.trim().replace(/\u0020{2,}/,'\u0020').split('\u0020');
        }
        function calc() {
            var dim = getNumbers(document.getElementById("dimId").value);

            var a = dim[0], b = dim[1], c = dim[2], d = dim[3], e = dim[4], f = dim[5];

            var result = "";

            if (a / d != b / e) {

                var y = (f * a - d * c) / (e * a - d * b);
                var x = (c - b * y) / a;

                result = "Система имеет единственное решение: X = " +
                        x.toFixed(2) + ", Y = " + y.toFixed(2);

            } else if (a / d == c / f) {

                result = "Система имеет бесконечно много решений";

            } else {

                result = "Система не имеет решений";
            }

            document.getElementById("resultId").innerHTML = result;
        }
    </script>
</head>
<body>

<p>Решение системы уравнений:<br>
A * X + B * Y = C  и  D * X + E * Y = F</p>
<hr>
<p>Введите A B C D E F: <input id="dimId" size="15"></p>
<hr>
<p id="resultId"></p>

<button onclick="calc()">Рассчитать</button>

</body>
</html>



Назад · Задачи · Дальше

Personal tools
Namespaces

Variants
Actions
Navigation
Tools