Практикум по программированию. Основы. Ветвление. Система уравнений
From AsIsWiki
(Difference between revisions)
Line 58: | Line 58: | ||
<pre> | <pre> | ||
+ | // 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; | ||
+ | } | ||
</pre> | </pre> | ||
Revision as of 21:49, 12 April 2015
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; }
Pascal