How to read multiple numbers from single input line in C

1 Answer

0 votes
#include <stdio.h>

#define TOTAL 5

int main() {
    int arr[TOTAL] = { 0 };

    // Loop to read TOTAL integers from the user
    for (int i = 0; i < TOTAL; i++) {
        scanf_s("%d", &arr[i]);
    }

    for (int i = 0; i < TOTAL; i++) {
        printf("%d ", arr[i]);
    }

    return 0;
}



/*
run:

3 4 78 109 85
3 4 78 109 85

*/

 



answered Jan 26, 2025 by avibootz

Related questions

1 answer 109 views
3 answers 314 views
1 answer 144 views
1 answer 218 views
1 answer 136 views
2 answers 229 views
1 answer 146 views
...