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

From AsIsWiki
Revision as of 17:16, 14 March 2016 by Alex (Talk | contribs)

Jump to: navigation, search

Назад · Задачи


Contents

Java

import java.util.Scanner;

public class Task17 {

    public static void main(String[] args) {
        
        Scanner in = new Scanner(System.in);
        
	System.out.println();
        System.out.println("     Расчет напряженности");
        System.out.println(" электростатического поля сферы");
        System.out.println("--------------------------------");

        System.out.print(" Введите заряд сферы Q: "); 
	double q = in.nextDouble();

        System.out.print(" Введите радиус сферы R: "); 
	double r = in.nextDouble();

        System.out.println(" Расстояние от центра сферы"); 
        System.out.print(" до исследуемой точки L: "); 
	double l = in.nextDouble();

        System.out.println("--------------------------------");
        
	double e;
                    
	if (l >= r) {

	    e = q / (l * l);

	} else {

	    e = 0;

	}

	System.out.printf(" Напряженность поля E = %.2E в/м\n", e);
    }
}


C++

// g++ 4.2

#include <iostream>

using namespace std;

int main() {
    
    double q, r, l;
    
    cout << "\n     Расчет напряженности\n";
    cout << " электростатического поля сферы\n";
    cout << "--------------------------------\n";
    
    cout << " Введите заряд сферы Q: ";
    cin >> q;
    
    cout << " Введите радиус сферы R: ";
    cin >> r;
    
    cout << " Расстояние от центра сферы\n";
    cout << " до исследуемой точки L: ";
    cin >> l;
    
    cout << "--------------------------------\n";
    
    double e;
    
    if (l >= r) {

        e = q / (l * l);

    } else {

        e = 0;

    }
    
    printf(" Напряженность поля E = %.2E в/м\n\n", e);
    
    return 0;
}


Pascal



JavaScript




Назад · Задачи

Personal tools
Namespaces

Variants
Actions
Navigation
Tools