469,320 Members | 2,115 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,320 developers. It's quick & easy.

beg needs help: find the maximum value of an array

choke
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[0];
  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

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by abcd | last post: by
1 post views Thread by shauncarter1 | last post: by
13 posts views Thread by Chua Wen Ching | last post: by
2 posts views Thread by Martin Ho | last post: by
3 posts views Thread by inkexit | last post: by
5 posts views Thread by Sunny123 | last post: by
10 posts views Thread by napsterrafay | last post: by
15 posts views Thread by timothytoe | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by Gurmeet2796 | last post: by
reply views Thread by mdpf | last post: by
reply views Thread by listenups61195 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.