NAG Library Manual, Mark 27.2
```/* F01EF_P0W_F C++ Header Example Program.
*
* Copyright 2021 Numerical Algorithms Group.
* Mark 27.2, 2021.
*/

#include <iostream>
#include <math.h>
#include <nag.h>
#include <nagx04.h>
#include <stdio.h>
#include <string>
using namespace std;
extern "C"
{
static void NAG_CALL f(void *&        ad_handle,
Integer &      iflag,
const Integer &n,
const double   x[],
double         fx[],
Integer        iuser[],
double         ruser[]);
}
int main(void)
{
int     exit_status = 0;
Integer ifail       = 0;

cout << "F01EF_P0W_F C++ Header Example Program Results\n\n";
// Skip heading in data file
string mystr;
getline(cin, mystr);

// Read problem size and number of right-hand-sides
Integer n;
cin >> n;

// Allocate arrays containing A and its factorized form, B
// and the solution X.
double *a = 0;
a         = new double[n * n];

// Read the matrix A, register and copy
for (int i = 0; i < n; ++i)
{
for (int j = i; j < n; ++j)
{
Integer k = i + j * n;
cin >> a[k];
}
}
// Find f(A)
Integer iflag, iuser[1];
double  ruser[1];

ifail = 0;
ifail);

// Print f(A)
cout << endl;
NagError fail;
INIT_FAIL(fail);
x04cac(Nag_ColMajor, Nag_UpperMatrix, Nag_NonUnitDiag, n, n, a, n, "  f(A)",
0, &fail);

delete[] a;

return exit_status;
}
static void NAG_CALL f(void *&        ad_handle,
Integer &      iflag,
const Integer &n,
const double   x[],
double         fx[],
Integer        iuser[],
double         ruser[])
{
for (int i = 0; i < n; ++i)
{
fx[i] = cos(x[i]);
}
}
```