J
James
Hello,
First off, I know this code will not compile and am not asking for
someone to solve it for me.
What I am asking is from the code below, how does one first define an
array as a constant, and second pass the values in and out of
functions?
Here is the code; Thanks in advance:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
/* Constant declarations */
const int MIN_VALUE=0;
const int MAX_VALUE=500000;
const int* A[ ];
/* Variable Declarations */
int N;
int n;
int k;
int d;
/* Function Prototypes */
int valueprint (const int MIN_VALUE, const int MAX_VALUE, const int A[
], int N, int n, int k, int d);
int adder (int n, int k, int d);
int progression (int n, int k, int d);
int maxsubsequencesum (const A[ ], int N, int n, int k, int d);
/* Function Declarations */
int valueprint (const int MIN_VALUE, const int MAX_VALUE, const int A[
], int N, int n, int k, int d)
{
printf ("Values: \n");
printf ("MIN_VALUE MAX_VALUE A, N n k d \n");
printf (MIN_VALUE," ",MAX_VALUE," ",&A," ",N," ",n," ",k,"
",d,"\n");
return 0;
}
int progression (int n, int k, int d)
{
/* sum the els sequence */
for (n = MIN_VALUE; n <= MAX_VALUE; n++)
{
for (d=MIN_VALUE; d <= MAX_VALUE; d++)
{
d=2*d;
return d;
}
if (n > MAX_VALUE)
n = ( n + ( ( k - 1 ) * d) );
else
n = (n + d);
return n;
}
return 0;
}
int adder (int n, int k, int d)
{
printf ("ELS Solver Program\n");
n=3;
k=7;
d=n+k;
return 0;
}
int maxsubsequencesum ( const int A[ ], int N, int n, int k, int d)
{
int ThisSum, MaxSum, i, j;
MaxSum = 0;
i = n;
j = k;
N = d;
for ( i = 0; i < N; i++ );
{
ThisSum = 0;
for ( j = i; j < N; j++ )
{
ThisSum += A[ j ];
if ( ThisSum > MaxSum )
MaxSum = ThisSum;
}
}
return MaxSum;
}
/****************************************************/
/****************************************************/
/********** **********/
/********** MAIN PROGRAM **********/
/********** **********/
/***************************************************/
/***************************************************/
int main (void)
{
valueprint (A[ ],N,n,k,d);
adder(n,k,d);
valueprint (A[ ],N,n,k,d);
maxsubsequencesum (A[ ], N, n, k, d);
valueprint (A[ ],N,n,k,d);
printf ("\nMaxSum: ",MaxSum);
printf ("\n");
valueprint (A[ ],N,n,k,d);
}
/*********************************************/
/*********************************************/
/*********************************************/
First off, I know this code will not compile and am not asking for
someone to solve it for me.
What I am asking is from the code below, how does one first define an
array as a constant, and second pass the values in and out of
functions?
Here is the code; Thanks in advance:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
/* Constant declarations */
const int MIN_VALUE=0;
const int MAX_VALUE=500000;
const int* A[ ];
/* Variable Declarations */
int N;
int n;
int k;
int d;
/* Function Prototypes */
int valueprint (const int MIN_VALUE, const int MAX_VALUE, const int A[
], int N, int n, int k, int d);
int adder (int n, int k, int d);
int progression (int n, int k, int d);
int maxsubsequencesum (const A[ ], int N, int n, int k, int d);
/* Function Declarations */
int valueprint (const int MIN_VALUE, const int MAX_VALUE, const int A[
], int N, int n, int k, int d)
{
printf ("Values: \n");
printf ("MIN_VALUE MAX_VALUE A, N n k d \n");
printf (MIN_VALUE," ",MAX_VALUE," ",&A," ",N," ",n," ",k,"
",d,"\n");
return 0;
}
int progression (int n, int k, int d)
{
/* sum the els sequence */
for (n = MIN_VALUE; n <= MAX_VALUE; n++)
{
for (d=MIN_VALUE; d <= MAX_VALUE; d++)
{
d=2*d;
return d;
}
if (n > MAX_VALUE)
n = ( n + ( ( k - 1 ) * d) );
else
n = (n + d);
return n;
}
return 0;
}
int adder (int n, int k, int d)
{
printf ("ELS Solver Program\n");
n=3;
k=7;
d=n+k;
return 0;
}
int maxsubsequencesum ( const int A[ ], int N, int n, int k, int d)
{
int ThisSum, MaxSum, i, j;
MaxSum = 0;
i = n;
j = k;
N = d;
for ( i = 0; i < N; i++ );
{
ThisSum = 0;
for ( j = i; j < N; j++ )
{
ThisSum += A[ j ];
if ( ThisSum > MaxSum )
MaxSum = ThisSum;
}
}
return MaxSum;
}
/****************************************************/
/****************************************************/
/********** **********/
/********** MAIN PROGRAM **********/
/********** **********/
/***************************************************/
/***************************************************/
int main (void)
{
valueprint (A[ ],N,n,k,d);
adder(n,k,d);
valueprint (A[ ],N,n,k,d);
maxsubsequencesum (A[ ], N, n, k, d);
valueprint (A[ ],N,n,k,d);
printf ("\nMaxSum: ",MaxSum);
printf ("\n");
valueprint (A[ ],N,n,k,d);
}
/*********************************************/
/*********************************************/
/*********************************************/