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

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

Jump to: navigation, search

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


Contents

Java

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++

// 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



JavaScript




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

Personal tools
Namespaces

Variants
Actions
Navigation
Tools