How to read in an int N followed by N doubles in C all in one line? -


for example, need read line like:

<n> [<double>]+ 

for example:

1 2.3 

or

4 -1.2 2.5 7.3 -3.0 

where 4 number of elements following int 4 in case.

then want store these values in array. i've tried doing this:

int i, n;      scanf("%d",&n);     double vals[n];      //read in doubles     (i=0; < n; i++) {         scanf("%lf", &vals[i]);     }     //print     (i=0; < n; i++) {         printf("%.3lf\n", vals[i]);     } 

but when print out values 0..


Comments

Popular posts from this blog

sql server - Cannot query correctly (MSSQL - PHP - JSON) -

php - trouble displaying mysqli database results in correct order -

C++ Linked List -