fork download
  1. #include <iostream>
  2. #include <array>
  3.  
  4. template<typename T, size_t SZ> void timesTwo(std::array<T, SZ>& arr) {
  5. for (auto& a : arr) {
  6. a *= 2;
  7. }
  8. }
  9.  
  10.  
  11. int main() {
  12. std::array<int, 5> arr1 = { 1, 2, 3, 4, 5 };
  13.  
  14. std::array<int, 16> arr2;
  15. arr2.fill(0);
  16. for (int i = 1; i < 16; i++) {
  17. int temp = arr2[i - 1] * 2;
  18. arr2[i] = (temp ? temp : 1);
  19. }
  20.  
  21. std::array<float, 3> arr3 = { 1.1, 2.2, 3.3 };
  22.  
  23. timesTwo(arr1);
  24. timesTwo(arr2);
  25. timesTwo(arr3);
  26.  
  27. for (auto& a : arr1) {
  28. std::cout << a << " ";
  29. }
  30. std::cout << std::endl;
  31.  
  32. for (auto& a : arr2) {
  33. std::cout << a << " ";
  34. }
  35. std::cout << std::endl;
  36.  
  37. for (auto& a : arr3) {
  38. std::cout << a << " ";
  39. }
  40. std::cout << std::endl;
  41. }
Success #stdin #stdout 0s 3412KB
stdin
Standard input is empty
stdout
2 4 6 8 10 
0 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 
2.2 4.4 6.6