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

From AsIsWiki
Revision as of 11:44, 21 March 2016 by Alex (Talk | contribs)

Jump to: navigation, search

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


Contents

 [hide

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
import java.util.Scanner;
 
public class Task02 {
 
    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 p = 1;
 
        for (long i = 1; i <= n; i++) {
            p *= i;
        }
 
        System.out.println("-------------------");
        System.out.printf(" %d! = %d\n", n, p);
    }
}


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
// g++ 4.2
 
#include <iostream>
 
using namespace std;
 
int main() {
     
    long n;
     
    cout << "\n Расчет факториала\n";
    cout << "-------------------\n";
     
    cout << " Введите число: ";
    cin >> n;
     
    long p = 1;
     
    for (long i = 1; i <= n; i++) {
        p *= i;
    }
 
    cout << "-------------------\n";
    printf(" %ld! = %ld\n\n", n, p);
     
    return 0;
}


Pascal

1
 


JavaScript

1
 



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

Personal tools
Namespaces

Variants
Actions
Navigation
Tools