Практикум по программированию. Основы. Циклы. Расчет масс деталей

From AsIsWiki
Jump to: navigation, search

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


Contents

Java

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

public class Task13 {

    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);

        System.out.println();
        System.out.println(" Рассчет массы деталей");
        System.out.println("-----------------------");

        System.out.print(" Плотность материала: ");
        double p = in.nextDouble();

        System.out.print(" Радиус основания: ");
        double r = in.nextDouble();

        System.out.print(" Предельная высота: ");
        int h = in.nextInt();

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

        double m;

        for (int i = 1; i <= h; i++) {

            m = p * i * Math.PI * r * r;

            System.out.printf(" Деталь N%d имеет массу m = %.2f\n", i, m);

        }
    }
}


C++

// g++ 4.2

#include <iostream>
#include <math.h>

using namespace std;

int main() {
    
    double p, r;
    int h;
    
    cout << "\n Рассчет массы деталей\n";
    cout << "-----------------------\n";
    
    cout << " Плотность материала: ";
    cin >> p;
    
    cout << " Радиус основания: ";
    cin >> r;
    
    cout << " Предельная высота: ";
    cin >> h;
    
    cout << "-----------------------\n";
    
    double m;
    
    for (int i = 1; i <= h; i++) {
    
        m = p * i * M_PI * r * r;
        
        printf(" Деталь N%d имеет массу m = %.2f\n", i, m);
        
    }
    
    cout << "\n";
    return 0;
}


Pascal



JavaScript




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

Personal tools
Namespaces

Variants
Actions
Navigation
Tools