I do not know where the problem lies
int main()
{
int antalVarde = 0;
low=0, high=0;
float* arr;
srand((int)time(NULL));
printf("Hur många värden ska skapas: ");
scanf_s("%d", &antalVarde);
printf("Ange min-värde: ");
scanf_s("%d", &low);
printf("Ange max-värde: ");
scanf_s("%d", &high);
arr = (float*)malloc(antalVarde * sizeof(float));
for (int i = 0; i <= antalVarde; i++)
{
*arr = RandomReal(low, high);
}
printf("%f", *arr);
getchar();
return 0;
}
float RandomReal(float low, float high)
{
float d;
d = (float) rand() / ((float) RAND_MAX + 1);
return (low + d * (high - low));
}
Aucun commentaire:
Enregistrer un commentaire