Skip to content

Instantly share code, notes, and snippets.

@meehatpa
Last active November 17, 2023 09:32
Show Gist options
  • Save meehatpa/902ac4af0a7845f56da4071dc57e147b to your computer and use it in GitHub Desktop.
Save meehatpa/902ac4af0a7845f56da4071dc57e147b to your computer and use it in GitHub Desktop.
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
const int M = 10;
const int N = 64;
float simple(float A[][N], int m, int n) {
float sum = 0;
for (int i = 0; i < m; i++)
for (int j = 0; j < n; j++)
sum += A[i][j];
return sum;
}
float psum(float A[][N], int m, int n) {
float psum[M] = {0};
for (int i = 0; i < m; i++)
for (int j = 0; j < n; j++)
psum[i] += A[i][j];
float sum = 0;
for (int i = 0; i < m; i++)
sum += psum[i];
return sum;
}
int main() {
float A[M][N];
for (int i = 0; i < M; i++)
for (int j = 0; j < N; j++)
A[i][j] = 0.1;
std::cout.precision(std::numeric_limits<float>::max_digits10);
cout << simple(A, M, N) << "\n";
cout << psum(A, M, N) << "\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment