The number of elements to declare an array after declaring the 10 individuals from the keyboard to enter data?

c language programming

3 Answers

Relevance
  • 9 years ago
    Favorite Answer

    I'm assuming you wish to store elements of data entered by ten people. You'd need an array of two dimensions to do this; the first array element to identify the user, and the second element to store that user's data.

    In very simple terms, it would work like this for 10 users with 100 records per user (BASIC pseudo code assuming strings for both user and data):

    number_of_users = 10

    inputs_per_user = 100

    DIM data$(number_of_users,inputs_per_user)

    etc...

    So, e.g. if you then wanted to look at the 68th data entry from the 3rd user, you would find the data in:

    data$(3,68)

    Hope this helps, and that I have understood your question correctly.

  • Nunya
    Lv 7
    9 years ago

    Above user is wrong..

    cin >> arraySize; is c++, not C, two entirely different languages

    to do it do this:

    numIndividuals = 10;

    int *A = malloc (sizeof (int) * numIndividuals);

    int i;

    for (i = 0; i < numIndividuals; i++)

    {A[i] = i;}

    to make a dynamic size array, you have to malloc 10 integer memory locations. This will give you a pointer which will point to the array's first location. It is rather stupid to have to do it this way but if you just declare an array with a variable assigned length, then it won't work in some machines and it will in others.

    Google "dynamically allocated array in c" for more info.

  • Anonymous
    9 years ago

    hmm?

    i guess you mean dynamic arrays?

    int * myArray;

    int arraySize;

    cin >> arraySize;

    myArray = new int[arraySize];

Still have questions? Get your answers by asking now.