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

From AsIsWiki
(Difference between revisions)
Jump to: navigation, search
Line 14: Line 14:
  
 
     public static void main(String[] args) {
 
     public static void main(String[] args) {
       
+
 
 
         Scanner in = new Scanner(System.in);
 
         Scanner in = new Scanner(System.in);
       
+
 
System.out.println();
+
        System.out.println();
         System.out.println(" Решение системы уравнений:             ");
+
         System.out.println(" Решение системы уравнений:");
         System.out.println(" A * X + B * Y = C  и  D * X + E * Y = F ");
+
         System.out.println(" A * X + B * Y = C  и  D * X + E * Y = F");
 
         System.out.println("-----------------------------------------");
 
         System.out.println("-----------------------------------------");
  
         System.out.print(" Введите A B C D E F: ");  
+
         System.out.print(" Введите A B C D E F: ");
double a = in.nextDouble();
+
        double a = in.nextDouble();
double b = in.nextDouble();
+
        double b = in.nextDouble();
double c = in.nextDouble();
+
        double c = in.nextDouble();
double d = in.nextDouble();
+
        double d = in.nextDouble();
double e = in.nextDouble();
+
        double e = in.nextDouble();
double f = in.nextDouble();
+
        double f = in.nextDouble();
  
 
         System.out.println("-----------------------------------------");
 
         System.out.println("-----------------------------------------");
  
if (a / d != b / e) {
+
        if (a / d != b / e) {
  
    double y = (f * a - d * c) / (e * a - d * b);
+
            double y = (f * a - d * c) / (e * a - d * b);
      double x = (c - b * y) / a;
+
            double x = (c - b * y) / a;
  
    System.out.printf(" Система имеет единственное решение X = %.2f, Y = %.2f\n", x, y);
+
            System.out.printf(
 +
                    " Система имеет единственное решение X = %.2f, Y = %.2f\n", x, y);
  
} else {
+
        } else if (a / d == c / f) {
    if (a / d == c / f) {
+
  
System.out.println(" Система имеет бесконечно много решений");
+
            System.out.println(" Система имеет бесконечно много решений");
  
    } else {
+
        } else {
  
System.out.println(" Система не имеет решений");
+
            System.out.println(" Система не имеет решений");
  
    }
+
        }
}
+
 
     }
 
     }
 
}
 
}
Line 80: Line 79:
 
          
 
          
 
         double y = (f * a - d * c) / (e * a - d * b);
 
         double y = (f * a - d * c) / (e * a - d * b);
      double x = (c - b * y) / a;
+
        double x = (c - b * y) / a;
 
          
 
          
 
         printf(" Система имеет единственное решение X = %.2f, Y = %.2f", x, y);
 
         printf(" Система имеет единственное решение X = %.2f, Y = %.2f", x, y);
 
          
 
          
     } else {
+
     } else if (a / d == c / f) {
        if (a / d == c / f) {
+
 
              
 
              
            cout << " Система имеет бесконечно много решений";
+
        cout << " Система имеет бесконечно много решений";
 
              
 
              
        } else {
+
    } else {
 
              
 
              
            cout << " Система не имеет решений";
+
        cout << " Система не имеет решений";
 
              
 
              
        }
 
 
     }
 
     }
 
      
 
      

Revision as of 03:26, 16 March 2016

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


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



JavaScript




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

Personal tools
Namespaces

Variants
Actions
Navigation
Tools