RE: [Dev-C++] Using Command Line to Execute program
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: <Ech...@ne...> - 2001-11-15 21:41:52
|
I assume you mean to compile it, and that the program is in a file called harmonic.c
Since dev-cpp uses gcc as it's compiler, I think you would youise the following command, from the file's directory:
gcc harmonic.c -o harmonic.exe
however, since it is a windows compiler, it might need other options? :-)
---- message follows ----
Please show me step-by-step how to use DevC++ to run a program through
Command Line method fpr the following program. Thank you!!!!!!!!!!!!!!
#include <iostream.h>
#include <stdlib.h>
#include <stdio.h>
//----------------------------------------------------------------------------
----
// array passed as pointer
float sum_array( float *A, int len )
{
float s = 0;
for( int i = 0; i < len; ++i )
s += A[i];
return s;
}
// array passed as array of unspecified length
float average_array( float A[], int len )
{
return sum_array( A, len )/len;
}
//----------------------------------------------------------------------------
----
void main( int argc, char **argv )
{
if( argc != 1 )
{
cerr << "Usage: " << argv[0] << " number" << endl;
cerr <<"int argc: "<<argc;
getchar();
exit(0);
}
int n = atoi( argv[1] );
float H[n];
for( int i = 1; i <= n; ++i )
H[i-1] = 1/float(i);
cout << "harmonic number " << n << ": " << sum_array( H, n ) << endl;
cout << "average 1/i up to " << n << ": " << average_array( H, n ) <<
endl;
exit(0);
}
//--------------------------------
------------------------------------------------
--
__________________________________________________________________
Your favorite stores, helpful shopping tools and great gift ideas. Experience the convenience of buying online with Shop@Netscape! http://shopnow.netscape.com/
Get your own FREE, personal Netscape Mail account today at http://webmail.netscape.com/
|