[Solved] Is it possible to run scanf like this? [closed]


I think this is what you are trying to do:

int main() {

    int numList[5];
    int i;
    for(i = 0; i < 5; i++) {
        printf("Input number %d ",i);
        scanf("%d",&a[i]);
    }
    printf("Your numbers: ");
    for(i = 0; i < 5; i++) {
         printf("%d, ",a[i]);
    }
    printf("\n");
}

The method that I used for printing is quick and arbitrary, but you could also use:

printf("Your numbers are: %d,%d,%d,%d,%d.\n",a[0],a[1],a[2],a[3],a[4]);

to get the same result.

For the printf function: 1 %d means you need 1 integer listed after the quote, 2 for 2, and so on.

Definitely read up on arrays, they save so much time.

Also note that the second command in

for(i=1;i=a;i++)

is assigning the value of a to i which is nonsensical. This will also always result in the for loop contents being run, unless it fails due to not being initialized as Filipe Gonçalves pointed out.

2

solved Is it possible to run scanf like this? [closed]