Last active
November 23, 2023 08:49
-
-
Save juanfal/9a4dcd2f17558ffce53b4793fe3ccba7 to your computer and use it in GitHub Desktop.
Open arrays
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// t12e06.OpenArray.cpp | |
// juanfc 2023-11-23 | |
// | |
#include <array> | |
#include <iostream> | |
using namespace std; | |
const int N = 100; | |
typedef array<int, N> TVector; | |
struct TOpenArr { | |
int noelems; | |
TVector ar; | |
}; | |
void printOArr(TOpenArr a); | |
TOpenArr sumOArr(TOpenArr a, TOpenArr b); | |
int main() | |
{ | |
TOpenArr a = {3, {{1, 2, 3}}}; | |
TOpenArr b = {3, {{3, 2, 1}}}; | |
printOArr(sumOArr(a, b)); | |
} | |
TOpenArr sumOArr(TOpenArr a, TOpenArr b) | |
{ | |
TOpenArr r = {a.noelems}; | |
for (int i = 0; i < a.noelems; ++i) | |
r.ar[i] = a.ar[i] + b.ar[i]; | |
return r; | |
} | |
void printOArr(TOpenArr a) | |
{ | |
for (int i = 0; i < a.noelems; ++i) | |
cout << a.ar[i] << " "; | |
cout << endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment