## Wednesday, November 24, 2010

### MathLink Example 2: Sum a list of floating point numbers

This example considers a sum of of floating point numbers.
----------------------------------------------------------------
----------------------------------------------------------------

```#include "mathlink.h"

{
int i,n;

double *list;

double sum=0;
for(i=0;i<n;i++) sum = sum + list[i];

return sum;
}

#if __BORLANDC__
#pragma argsused
#endif

int PASCAL WinMain( HINSTANCE hinstCurrent, HINSTANCE hinstPrevious, LPSTR lpszCmdLine, int nCmdShow)
{

char  buff[512];
char FAR * buff_start = buff;

char FAR * argv[32];
char FAR * FAR * argv_end = argv + 32;

hinstPrevious = hinstPrevious; /* suppress warning */

if( !MLInitializeIcon( hinstCurrent, nCmdShow)) return 1;

MLScanString( argv, &argv_end, &lpszCmdLine, &buff_start);
return MLMain( (int)(argv_end - argv), argv);
}

#else

int main(int argc, char* argv[])
{

return MLMain(argc, argv);
}

#endif```

------------------------------------------------------
------------------------------------------------------

```:Begin:

:Arguments:      { L  }
:ArgumentTypes:  { Manual  }
:ReturnType:     Real

:End:

:Evaluate: addRealList::usage = "addRealList[x] gives the sum of the elements on x, given that they are real (double floating numbers)"```

------------------------------------------
Makefile
------------------------------------------
```MPREP = /usr/bin/mprep
CXX = /usr/bin/c++

clean:

```

--------------------------------------------------------