I have an int array called `doubledNumbers` and if a number in this array is greater than 9, I want to add the digits together. (example, 16 would become 1+6=7, 12 would become 3, 14 would become 5, etc)

Lets say I had the following numbers in `doubledNumbers`:

```
12 14 16 17

```

I want to change the `doubledNumbers` to:

```
3 5 7 8

```

I'm unsure how to do this for an int array as I get the error 

> 
> invalid types 'int[int]' for array subscript
> 
> 
> 

This is the code I have (thrown in a `for` loop):

```
  if (doubledNumbers[i]>9) {
       doubledNumbers[i]=doubledNumbers[i][0]+doubledNumbers[i][1];

```
['https://Stackoverflow.com/questions/30723972', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/3681431/']
You can use something like this

```
#include <iostream>
using namespace std;
int sumofdigits(int);
int main() 
{
    // your code goes here
    int a[5] ={12,14,15,16,17};
    for(int i=0;i<5;i++)
    {
        int m=sumofdigits(a[i]);
        cout <<m<<" ";
    }
        return 0;
}
int sumofdigits(int n)
{

        int sum=0;
        while(n!=0)
       {
            int d=n%10;
            sum=sum+d;
            n=n/10;
        }
        return sum;
}

```

// % operator is used for calculating remainder.
```
int A[2];
A[0] = 2;
A[1] = 10;
for (int i=0;i<2;i++) {
    if (a[i] > 9) {
        int b = a[i]%10;
        int c = a[i]/10; 
        int d = b+c;
        cout << d;
    }
}

```

It's only for two digit numbers(10 -99) and for more than that (after 99) we will have to change logic.