469,320 Members | 2,115 Online

# beg needs help: find the maximum value of an array 8
I need to write a function in devc++ that creates an array of n integers, each element is equal to n*n+i*i-n*i where i is from 0 to n-1 as the array index. Within the same function I need to find the maximum value, minimum value and average of all elements. I'm stuck on the first one :/ I've practiced calling another function to find the maximum, and that seemed to work fine. I get a number in the millions when trying to do this all in one function...can anyone help? Also, shouldn't I be able to do the if statement with the first for loop?

Expand|Select|Wrap|Line Numbers
1. int array(int n)
2. {
3.
4. const int SIZE=n;
5. int arrayofn[SIZE];
6.
7. int i, j, max, min;
8. cout<<"Your array=";
9.    for (i=0; i<=n-1; i++)
10.    {
11. arrayofn[SIZE]=n*n+i*i-n*i;
12.
13. cout<<arrayofn[SIZE]<<" ";
14. }
15. cout<<"\n";
16.
17. max=arrayofn;
18. for (j=1; j<SIZE; j++)
19.
20. {
21.     if (max<arrayofn[j])
22.     max=arrayofn[j];
23. }
24. cout<<"The maximum value in the array is: "<<max<<"\n";
25.
26. }
27.
Oct 15 '07 #1
2 2282 weaknessforcats
9,208 Expert Mod 8TB
arrayofn[SIZE]=n*n+i*i-n*i;
You may have misunderstood the problem.

I read it that arrayofn[i] is the n. So:

arrayofn[i] = arrayofn[i] * arrayofn[i] + i*i - arrayofn[i] *i

What do you think?
Oct 15 '07 #2
choke
8 You may have misunderstood the problem.

I read it that arrayofn[i] is the n. So:

arrayofn[i] = arrayofn[i] * arrayofn[i] + i*i - arrayofn[i] *i

What do you think?

No, but that did alert me that it should've been:

arrayofn[i]=n-1+n*i-i*i

durr...*finds a bigger fine toothed comb*

Thanks!
Oct 15 '07 #3