fork download
  1. #include <iostream>
  2. #include <algorithm>
  3.  
  4. int main()
  5. {
  6.  
  7. //int i, j;
  8. int sum = 0;
  9. const int num = 36;
  10. int* myDataX = new int[num];
  11. int* myDataY = new int[num];
  12. float value = 0;
  13.  
  14.  
  15.  
  16. for (int a = 0; a < num; a++)
  17. {
  18. myDataX[a] = a;
  19. myDataY[a] = a;
  20. }
  21.  
  22. for (int i = 0; i < num; i++)
  23. {
  24. float x = myDataX[i];
  25.  
  26. for (int j = 0; j < num; j++)
  27. {
  28. float y = myDataY[j];
  29. value = x + y;
  30. sum += value;
  31. }
  32.  
  33. }
  34.  
  35. std::cout << "sum: " << sum << std::endl;
  36.  
  37. sum = (std::accumulate(myDataX, myDataX + num, 0.f) + std::accumulate(myDataY, myDataY + num, 0.f)) * num;
  38.  
  39. std::cout << "sum: " << sum << std::endl;
  40.  
  41. return 0;
  42. }
Success #stdin #stdout 0s 3456KB
stdin
Standard input is empty
stdout
sum: 45360
sum: 45360