Trouble with array...

I have set of 5 integers I want to be declare as array elements, and I want each following element in the array to preform arithmetic, say simply subtract 20 from each of them, while the first is set to 100.
So the 5th and final element would be set to 20..
Last edited on
I have set of 5 integers I want to be declare as array elements
int arr[]={100,80,60,40,20}
Here's another option -> http://ideone.com/QTKmp5
use a for loopfor(int x=0;x<5;x++)
@m4ster r0shi nice lol ;)
I know. Thanks.
I think xplainet's head is boiling lol
1
2
3
4
5
6
7
8
9
 
    int j[5];
    int n, i;
    i = 0;
    for (n = 0; n < 5; ++n) {
        j[n] = 100 - i;
        cout << j[n] << " ";
        i = i + 20;
        }


Maybe that could help you, too.
@chriscpp I was actually referring to a way to make each elements in the array more variable.
say I have an alternating variable that would change each value of the array.
So if a variables value is 2, each array will divide the previous by 2. If it changes to 3, each element in the array would divide the previous by 3.
Or add, multiply whatever.
The idea is to set the array elements to certain possible X values for the f(x)


Also: is there some way to collect each value of the array and set the sum of each to another variable?
Last edited on
is there some way to collect each value of the array and set the sum of each to another variable?

Sure -> http://ideone.com/FB31nC (if I correctly understood what you want...)

Useful link -> http://www.cplusplus.com/reference/numeric/accumulate/
Last edited on
Topic archived. No new replies allowed.