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

From AsIsWiki
(Difference between revisions)
Jump to: navigation, search
Line 83: Line 83:
  
 
<source lang="js">
 
<source lang="js">
 +
<html lang="ru">
 +
<head>
 +
    <meta charset="UTF-8">
 +
    <script>
 +
        function calc() {
 +
            var n = document.getElementById("nId").value;
 +
 +
            var i = 2;
 +
 +
            while ((i <= n / 2) && (n % i != 0)) {
 +
                i++;
 +
            }
 +
 +
            var no = i <= n / 2 ? "не " : "";
 +
 +
            document.getElementById("resultId").innerHTML =
 +
                    " Число " + n + " - " + no + "простое";
 +
        }
 +
    </script>
 +
</head>
 +
<body>
 +
 +
<p>Поиск простых чисел</p>
 +
<hr>
 +
<p>Введите число: <input id="nId" size="5"></p>
 +
<hr>
 +
<p id="resultId"></p>
 +
 +
<button onclick="calc()">Рассчитать</button>
 +
 +
</body>
 +
</html>
 
</source>
 
</source>
  

Revision as of 08:21, 23 March 2016

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


Contents

Java

import java.util.Scanner;

public class Task06 {

    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);

        System.out.println();
        System.out.println(" Поиск простых чисел");
        System.out.println("---------------------");

        System.out.print(" Введите число: ");
        long n = in.nextLong();

        long i = 2;

        while ((i <= n / 2) && (n % i != 0)) {
            i++;
        }

        String no = i <= n / 2 ? "не " : "";

        System.out.println("---------------------");
        System.out.printf(" Число %d - %sпростое\n", n, no);
    }
}


C++

// g++ 4.2

#include <iostream>

using namespace std;

int main() {
    
    long n;
    
    cout << "\n Поиск простых чисел\n";
    cout << "---------------------\n";
    
    cout << " Введите число: ";
    cin >> n;
    
    long i = 2;
    
    while ((i <= n / 2) && (n % i != 0)) {
        i++;
    }
    
    string no = i <= n / 2 ? "не " : "";
    
    cout << "---------------------\n";
    printf(" Число %ld - %sпростое\n\n", n, no.data());
    
    return 0;
}


Pascal



JavaScript

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

            var i = 2;

            while ((i <= n / 2) && (n % i != 0)) {
                i++;
            }

            var no = i <= n / 2 ? "не " : "";

            document.getElementById("resultId").innerHTML = 
                    " Число " + n + " - " + no + "простое";
        }
    </script>
</head>
<body>

<p>Поиск простых чисел</p>
<hr>
<p>Введите число: <input id="nId" size="5"></p>
<hr>
<p id="resultId"></p>

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

</body>
</html>



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

Personal tools
Namespaces

Variants
Actions
Navigation
Tools