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

From AsIsWiki
(Difference between revisions)
Jump to: navigation, search
Line 41: Line 41:
  
 
<pre>
 
<pre>
 +
// g++ 4.2
 +
 +
#include <iostream>
 +
 +
using namespace std;
 +
 +
int main() {
 +
   
 +
    long n;
 +
   
 +
    cout << "\n Расчет факториала\n";
 +
    cout << "-------------------\n";
 +
   
 +
    cout << " Введите число: ";
 +
    cin >> n;
 +
   
 +
    cout << "-------------------\n";
 +
   
 +
    long p = 1;
 +
   
 +
    for (long i = 1; i <= n; i++) {
 +
        p *= i;
 +
    }
 +
   
 +
    printf(" %ld! = %ld\n\n", n, p);
 +
   
 +
    return 0;
 +
}
 
</pre>
 
</pre>
  

Revision as of 07:50, 14 April 2015

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


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();

        System.out.println("-------------------");
        
	long p = 1;

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

	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;
    
    cout << "-------------------\n";
    
    long p = 1;
    
    for (long i = 1; i <= n; i++) {
        p *= i;
    }
    
    printf(" %ld! = %ld\n\n", n, p);
    
    return 0;
}


Pascal




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

Personal tools
Namespaces

Variants
Actions
Navigation
Tools