Практикум по программированию. Основы. Циклы. Табулирование функции
From AsIsWiki
(Difference between revisions)
Line 73: | Line 73: | ||
return 0; | return 0; | ||
} | } | ||
+ | </source> | ||
+ | |||
+ | |||
+ | ==Python== | ||
+ | |||
+ | <source lang="cpp"> | ||
+ | # Python 3 | ||
+ | |||
+ | print('\n Табулирование функции Y = X^2 + 1') | ||
+ | print(' на отрезке [A, B] с шагом H') | ||
+ | print('-----------------------------------') | ||
+ | |||
+ | a, b = input(' Введите границы отрезка A и B: ').split() | ||
+ | h = float(input(' Введите шаг табулирования H: ')) | ||
+ | |||
+ | print('-----------------------------------') | ||
+ | print(' X Y') | ||
+ | |||
+ | a = float(a); b = float(b) | ||
+ | x = a; | ||
+ | while x <= b: | ||
+ | print(' %8.3f %8.3f' % (x, x * x + 1)) | ||
+ | x += h | ||
</source> | </source> | ||
Latest revision as of 09:26, 23 November 2017
Contents |
[edit] Java
import java.util.Scanner; public class Task08 { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.println(); System.out.println(" Табулирование функции Y = X^2 + 1"); System.out.println(" на отрезке [A, B] с шагом H"); System.out.println("-----------------------------------"); System.out.print(" Введите границы отрезка A и B: "); double a = in.nextDouble(); double b = in.nextDouble(); System.out.print(" Введите шаг табулирования H: "); double h = in.nextDouble(); System.out.println("-----------------------------------"); System.out.println(" X Y"); for (double x = a; x <= b; x += h) { System.out.printf(" %8.3f %8.3f\n", x, x * x + 1); } } }
[edit] C++
// g++ 4.2 #include <iostream> using namespace std; int main() { double a, b, h; cout << "\n Табулирование функции Y = X^2 + 1\n"; cout << " на отрезке [A, B] с шагом H\n"; cout << "-----------------------------------\n"; cout << " Введите границы отрезка A и B: "; cin >> a >> b; cout << " Введите шаг табулирования H: "; cin >> h; cout << "-----------------------------------\n"; cout << " X Y\n"; for (double x = a; x <= b; x += h) { printf(" %8.3f %8.3f\n", x, x * x + 1); } cout << "\n"; return 0; }
[edit] Python
# Python 3 print('\n Табулирование функции Y = X^2 + 1') print(' на отрезке [A, B] с шагом H') print('-----------------------------------') a, b = input(' Введите границы отрезка A и B: ').split() h = float(input(' Введите шаг табулирования H: ')) print('-----------------------------------') print(' X Y') a = float(a); b = float(b) x = a; while x <= b: print(' %8.3f %8.3f' % (x, x * x + 1)) x += h
[edit] Pascal
[edit] JavaScript