1. ## static array list

I'm trying to make static list that can add element in list. I know that's know the good way to make list but it's just experiment

only 5 digits allow in list

Program supposed to give result like this

add digit 1 in array then show array = 1
add digit 2 in array then show array = 1 2
add digit 3 in array then show array = 1 2 3
add digit 4 in array then show array = 1 2 3 4
add digit 5 in array then show array = 1 2 3 4 5

When array exceed limit size, stop adding digit

Code:
```#include<stdio.h>

int main ()
{
int i;

int array[5];

return 0;
}```
I need a function that add one digit in array and show the array digits

I'm stuck with function I don't understand what's logic need to add one digit

2. To add first digit => array[0] = 1
To add second digit => array[1] = 2
and so on until 5th digit which will be in array[4]

To print the array use a simple for loop.

3. Originally Posted by thmm
To add first digit => array[0] = 1
To add second digit => array[1] = 2
and so on until 5th digit which will be in array[4]

To print the array use a simple for loop.
I can do that but I am looking for a function

Code:
```#include<stdio.h>

int main ()
{
int i;

int array[5] = {1};

for ( i = 0; i <5; i++)
printf(" %d", array[i]);

array[1] = 2;

printf("\n");

for ( i = 0; i <5; i++)
printf(" %d", array[i]);

array[2] = 3;

printf("\n");

for ( i = 0; i <5; i++)
printf(" %d", array[i]);

array[3] = 4;

printf("\n");

for ( i = 0; i <5; i++)
printf(" %d", array[i]);

array[4] = 5;

printf("\n");

for ( i = 0; i <5; i++)
printf(" %d", array[i]);

return 0;
}```
1 0 0 0 0
1 2 0 0 0
1 2 3 0 0
1 2 3 4 0
1 2 3 4 5

4. Maybe:
Code:
```#include <stdio.h>

void push(int *a, int *size, int value) {
a[(*size)++] = value;
}

void print(const int *a, int size) {
while (size-- > 0) printf("%d ", *a++);
putchar('\n');
}

#define CAPACITY 5

int main() {
int a[CAPACITY], size = 0;
for (int i = 1; i <= CAPACITY; ++i) {
push(a, &size, i);
print(a, size);
}
return 0;
}```

5. Originally Posted by john.c
Maybe:
How do you do if number is not in sequence ?

2
2 9
2 9 3
2 9 3 6
2 9 3 6 5

6. Push whatever values you want. I just used a counting loop.