Advertisement
HyperSensualNarwhal

Untitled

Jan 20th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.08 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctime>
  3.  
  4. #pragma once
  5.  
  6. using std::cout;
  7. using std::cin;
  8. using std::endl;
  9.  
  10. #define TAB '\t'
  11. #define E2 cout << "\n\n"
  12. #define E4 cout << "\n\n\n\n"
  13.  
  14. const int sz = 10;
  15.  
  16.  
  17. template <typename T>
  18. T printArray(T arr[]);
  19.  
  20. template <typename T>
  21. T fillRandom(T arr[]);
  22.  
  23. int raiseToPower(int a, int b);
  24.  
  25. #include "Experimental.h"
  26.  
  27.  
  28. template <typename T>
  29. T fillRandom(T arr[])
  30.  
  31. {
  32.     for (int i = 0; i < sz; ++i)
  33.         arr[i] = rand() % 100;
  34.     return 0;
  35. }
  36.  
  37. template <typename T>
  38. T printArray(T arr[])
  39. {
  40.     for (int i = 0; i < sz; ++i)
  41.         cout << arr[i] << TAB;
  42.     return 0;
  43. }
  44.  
  45.  
  46. #include "Experimental.h"
  47. #include "functions.cpp"
  48.  
  49.  
  50. void main()
  51. {
  52.     srand(time(NULL));
  53.  
  54.     float alpha[sz];
  55.  
  56.     fillRandom<float>(alpha);
  57.     printArray<float>(alpha);
  58.     E4;
  59.  
  60.     int a = 5, b = 5, tmp = 1;
  61.  
  62.     for (int i = 0; i < b; ++i)
  63.         tmp *= a;
  64.     /*cout << tmp << endl;*/
  65.  
  66.     cout << raiseToPower(5, 3) << endl;
  67.  
  68. }
  69. //
  70. int raiseToPower(int a, int b)
  71. {
  72.     int tmp = a;
  73.    
  74.         if (b > 0)
  75.             return tmp *= raiseToPower(a, b - 1);
  76.         else
  77.             return 1;
  78.        
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement