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

From AsIsWiki
(Difference between revisions)
Jump to: navigation, search
 
Line 74: Line 74:
 
     return 0;
 
     return 0;
 
}
 
}
 +
</source>
 +
 +
 +
==Python==
 +
 +
<source lang="cpp">
 +
# Python 3
 +
 +
print('\n Вычисление степени с натуральным показателем A^N')
 +
print('--------------------------------------------------')
 +
 +
a = float(input(' Введите основание степени A: '))
 +
n = int(input(' Введите показатель степени N: '))
 +
 +
p = 1
 +
for i in range(1, n + 1):
 +
    p *= a
 +
 +
print('--------------------------------------------------')
 +
print(' A^N = %.2f' % p)
 
</source>
 
</source>
  

Latest revision as of 09:18, 23 November 2017

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


Contents

[edit] Java

import java.util.Scanner;

public class Task04 {

    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);

        System.out.println();
        System.out.println(" Вычисление степени с натуральным показателем A^N");
        System.out.println("--------------------------------------------------");

        System.out.print(" Введите основание степени A: ");
        double a = in.nextDouble();

        System.out.print(" Введите показатель степени N: ");
        long n = in.nextLong();

        double p = 1;

        for (long i = 1; i <= n; i++) {
            p *= a;
        }

        System.out.println("--------------------------------------------------");
        System.out.printf(" A^N = %.2f\n", p);
    }
}


[edit] C++

// g++ 4.2

#include <iostream>

using namespace std;

int main() {
    
    double a;
    long n;
    
    cout << "\n Вычисление степени с натуральным показателем A^N\n";
    cout << "--------------------------------------------------\n";
    
    cout << " Введите основание степени A: ";
    cin >> a;
    
    cout << " Введите показатель степени N: ";
    cin >> n;
    
    double p = 1;
    
    for (long i = 1; i <= n; i++) {
        p *= a;
    }

    cout << "--------------------------------------------------\n";
    printf(" A^N = %.2f\n\n", p);
    
    return 0;
}


[edit] Python

# Python 3

print('\n Вычисление степени с натуральным показателем A^N')
print('--------------------------------------------------')

a = float(input(' Введите основание степени A: '))
n = int(input(' Введите показатель степени N: '))

p = 1
for i in range(1, n + 1):
    p *= a

print('--------------------------------------------------')
print(' A^N = %.2f' % p)


[edit] Pascal



[edit] JavaScript

<html lang="ru">
<head>
    <meta charset="UTF-8">
    <script>
        function calc() {
            var a = document.getElementById("aId").value;
            var n = document.getElementById("nId").value;

            var p = 1;

            for (var i = 1; i <= n; i++) {
                p *= a;
            }

            document.getElementById("resultId").innerHTML = "A^N = " + p.toFixed(2);
        }
    </script>
</head>
<body>

<p>Вычисление степени с натуральным показателем A^N</p>
<hr>
<p>Введите основание степени A: <input id="aId" size="5"></p>
<p>Введите показатель степени N: <input id="nId" size="5"></p>
<hr>
<p id="resultId"></p>

<button onclick="calc()">Рассчитать</button>

</body>
</html>



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

Personal tools
Namespaces

Variants
Actions
Navigation
Tools