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

From AsIsWiki
(Difference between revisions)
Jump to: navigation, search
 
Line 15: Line 15:
  
 
     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("-----------------------");
 
         System.out.println("-----------------------");
  
         System.out.print(" Плотность материала: ");  
+
         System.out.print(" Плотность материала: ");
double p = in.nextDouble();
+
        double p = in.nextDouble();
  
         System.out.print(" Радиус основания: ");  
+
         System.out.print(" Радиус основания: ");
double r = in.nextDouble();
+
        double r = in.nextDouble();
  
         System.out.print(" Предельная высота: ");  
+
         System.out.print(" Предельная высота: ");
int h = in.nextInt();
+
        int h = in.nextInt();
  
 
         System.out.println("-----------------------");
 
         System.out.println("-----------------------");
       
 
for (int i = 1; i <= h; i++) {
 
  
    System.out.printf(" Деталь N%d имеет массу m = %.2f\n", i, p * i * Math.PI * r * r);
+
        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);
  
}
+
        }
 
     }
 
     }
 
}
 
}
Line 54: Line 58:
  
 
int main() {
 
int main() {
 
+
   
 
     double p, r;
 
     double p, r;
 
     int h;
 
     int h;
Line 71: Line 75:
 
      
 
      
 
     cout << "-----------------------\n";
 
     cout << "-----------------------\n";
 +
   
 +
    double m;
 
      
 
      
 
     for (int i = 1; i <= h; i++) {
 
     for (int i = 1; i <= h; i++) {
 +
   
 +
        m = p * i * M_PI * r * r;
 
          
 
          
         printf(" Деталь N%d имеет массу m = %.2f\n", i, p * i * M_PI * r * r);
+
         printf(" Деталь N%d имеет массу m = %.2f\n", i, m);
 
          
 
          
 
     }
 
     }
 
+
   
 
     cout << "\n";
 
     cout << "\n";
 
     return 0;
 
     return 0;

Latest revision as of 16:31, 22 March 2016

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


Contents

 [hide

[edit] Java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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);
 
        }
    }
}


[edit] C++

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// 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;
}


[edit] Pascal

1
 


[edit] JavaScript

1
 



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

Personal tools
Namespaces

Variants
Actions
Navigation
Tools