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

From AsIsWiki
Revision as of 09:26, 12 April 2015 by Alex (Talk | contribs)

Jump to: navigation, search

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


Contents

Java

import java.util.Scanner;
import java.lang.Math;

public class Task01 {

    public static void main(String[] args) {
        
        Scanner in = new Scanner(System.in);
        
	System.out.println();
        System.out.println(" Поиск корней уравнения A * X^2 + B * X + C = 0 ");
        System.out.println("------------------------------------------------");

        System.out.print(" Введите A: "); 
	double a = in.nextDouble();

        System.out.print(" Введите B: "); 
	double b = in.nextDouble();

        System.out.print(" Введите C: "); 
	double c = in.nextDouble();

        System.out.println("------------------------------------------------");
                            
	double d = b * b - 4 * a * c;
	double x1, x2;

	if (d > 0) {

	    x1 = (-b + Math.sqrt(d)) / (2 * a);
	    x2 = (-b - Math.sqrt(d)) / (2 * a);

	    System.out.printf(" X1 = %.3f\n", x1);
	    System.out.printf(" X2 = %.3f\n", x2);

	} else {
	    if (d == 0) {

		x1 = -b / (2 * a);

		System.out.printf(" X = %.3f\n", x1);

	    } else {

		System.out.println(" Уравнение корней не имеет");

	    }
	}
    }
}


C++



Pascal




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

Personal tools
Namespaces

Variants
Actions
Navigation
Tools