Hi I would like to write a small program that takes the input of integers and puts them in an array, from where one can do things like calculating their mean, median, standard deviation and so forth. My Problem is that, after extracting the numbers one by one, I am stuck at putting them in an array. One problem is that the array where I stored the numbers is only accessible in the for-loop, I would appreciate if someone could help. Here is it:

Code:
#include <iostream>
using namespace std;
int main(){
    int array[50], x, n, sum =0;
    cout << "Enter a number" << endl;
    cin >> x;
    int num = x;
    for(x; x !=0; x = x/10)  sum++;//Trying to find the number of digits given
    for(num; num != 0; num = num/10){
             n = num%10;
             array [sum - 1] = n; //I am trying to put in the numbers in an array 
             //in a back-to-front manner so I start with filling the last number in the array
             //and looping to the first array, i.e array[0] 
             sum--;
             cout << array[sum];
             }
             //But my Problem is that these variables are only valid within the for
             //loop so I can't access them outside of the for-loop although I need them
             // It would be grateful if someone can tell me how I can accessay array[sum]
             //outside of the for-loop.  
    return 0;
}