bogdan_obukhovskii

Untitled

Dec 26th, 2019
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <time.h>
  4. using namespace std;
  5.  
  6. int summ(int* a, int n)
  7. {
  8. int sum = 0;
  9.  
  10. for (int i = 0; i < n; i++)
  11. {
  12. sum += a[i];
  13. }
  14. return sum;
  15. }
  16.  
  17.  
  18. int main()
  19. {
  20. setlocale(0, "Rus");
  21. srand(time(0));
  22. int* mass;
  23. int n;
  24. cout << "Введите n" << endl;
  25. cin >> n;
  26. mass = new int[n];
  27.  
  28. cout << "Массив: " << endl;
  29. for (int i = 0; i < n; i++)
  30. {
  31. mass[i] = rand() % 10;
  32. cout << mass[i] << " ";
  33. }
  34.  
  35.  
  36. for (int i = 0; i < n; i++)
  37. {
  38. int pr = 1;
  39.  
  40. for (int j = 1; j <= mass[i]; j++)
  41. {
  42. pr *= j;
  43. }
  44. mass[i] = pr;
  45. }
  46.  
  47. cout << "Получившийся массив: ";
  48. for (int i = 0; i < n; i++)
  49. {
  50. cout << mass[i] << " "; //<< summ(num, n) << " ";
  51. }
  52. cout << endl << "сумма: " << summ(mass, n);
  53. system("pause");
  54. return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment