动态数组怎么存入随机数?为什么数组输出全是0?
#include <stdio.h>#include <time.h>
#include <stdlib.h>
int main()
{
int i;
int a;
int Len = 10;
double* input;
input = calloc(Len, sizeof * input);
int data;
int symbol;
srand((unsigned)time(NULL));
for (i = 0; i < Len; i++)
{
data = 1;
symbol = rand() % 100;
if (symbol % 2)
data = -data;
input[i] = data;
printf("%d\n", data);
}
for (a = 0; a < Len; a++)
{
printf("%d\n", input[a]);
}
free(input);
return 0;
}