Практикум по программированию. Основы. Ввод и вывод. Арифметическая прогрессия 1
From AsIsWiki
(Difference between revisions)
Line 105: | Line 105: | ||
var sn = n * (a1 + an) / 2; | var sn = n * (a1 + an) / 2; | ||
− | document.getElementById(" | + | document.getElementById("resultId").innerHTML = |
− | "A" + n + " = " + an.toFixed(2) | + | "A" + n + " = " + an.toFixed(2) + "<br>" + |
− | + | ||
"S" + n + " = " + sn.toFixed(2); | "S" + n + " = " + sn.toFixed(2); | ||
} | } | ||
Line 120: | Line 119: | ||
<p>Введите номер члена прогрессии: <input id="nId" size="5"></p> | <p>Введите номер члена прогрессии: <input id="nId" size="5"></p> | ||
<hr> | <hr> | ||
− | <p id=" | + | <p id="resultId"></p> |
− | + | ||
<button onclick="calc()">Рассчитать</button> | <button onclick="calc()">Рассчитать</button> |
Revision as of 11:12, 18 March 2016
Contents |
Java
import java.util.Scanner; public class Task09 { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.println(); System.out.println(" Арифметическая прогрессия"); System.out.println("---------------------------"); System.out.print(" Введите 1-ый член прогрессии: "); double a1 = in.nextDouble(); System.out.print(" Введите 5-ый член прогрессии: "); double a5 = in.nextDouble(); System.out.print(" Введите номер члена прогрессии: "); int n = in.nextInt(); System.out.println("---------------------------"); double d = (a5 - a1) / 4; double an = a1 + (n - 1) * d; double sn = n * (a1 + an) / 2; System.out.printf(" A%d = %.2f\n", n, an); System.out.printf(" S%d = %.2f\n", n, sn); } }
C++
// g++ 4.2 #include <iostream> using namespace std; int main() { double a1, a5; int n; cout << "\n Арифметическая прогрессия\n"; cout << "---------------------------\n"; cout << " Введите 1-ый член прогрессии: "; cin >> a1; cout << " Введите 5-ый член прогрессии: "; cin >> a5; cout << " Введите номер члена прогрессии: "; cin >> n; cout << "---------------------------\n"; double d = (a5 - a1) / 4; double an = a1 + (n - 1) * d; double sn = n * (a1 + an) / 2; printf(" A%d = %.2f\n", n, an); printf(" S%d = %.2f\n\n", n, sn); return 0; }
Pascal
JavaScript
<html lang="ru"> <head> <meta charset="UTF-8"> <script> function calc() { var a1 = Number(document.getElementById("a1Id").value); var a5 = Number(document.getElementById("a5Id").value); var n = Number(document.getElementById("nId").value); var d = (a5 - a1) / 4; var an = a1 + (n - 1) * d; var sn = n * (a1 + an) / 2; document.getElementById("resultId").innerHTML = "A" + n + " = " + an.toFixed(2) + "<br>" + "S" + n + " = " + sn.toFixed(2); } </script> </head> <body> <p>Арифметическая прогрессия</p> <hr> <p>Введите 1-ый член прогрессии: <input id="a1Id" size="5"></p> <p>Введите 5-ый член прогрессии: <input id="a5Id" size="5"></p> <p>Введите номер члена прогрессии: <input id="nId" size="5"></p> <hr> <p id="resultId"></p> <button onclick="calc()">Рассчитать</button> </body> </html>