Advertisement
Serafim_

Нахождение факториала

Oct 27th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.58 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. long long factorial(int n){
  5.     long long res = 1;
  6.     int i = 1;
  7.     while (i <= n){
  8.         res *= i;
  9.         i++;
  10.     }
  11.     return res;
  12. }
  13.  
  14.  
  15. void fill(int a[],int n){
  16.  
  17.     for (int i = 0; i < n+1; i++) {
  18.  
  19.         a[i] = factorial(i);
  20.     }
  21. }
  22.  
  23.  
  24. int main()
  25.  
  26.  
  27. {
  28.     int n;
  29.     cout << "Введите количество элементов массива : ";
  30.     cin >> n;
  31.     int * a = new int[n+1];
  32.  
  33.     fill(a, n);
  34.     for (int i = 0; i < n + 1; i++){
  35.         cout << a[i] << " ";
  36.     }
  37.     cout << endl;
  38.  
  39.  
  40.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement