#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <crtdbg.h>
int main(void)
{
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF |_CRTDBG_LEAK_CHECK_DF);
int request = 0;
printf("How many powers of two? ");
scanf("%d", &request);
float* p_array = 0;
p_array = malloc(sizeof(float)*request);
for (int k = 0; k < request; ++k)
{
p_array[k] = (powf(2, k));
}
for (int k = 0; k < request; ++k)
{
printf("%f\n", p_array[k]);
}
free(p_array);
p_array = 0;
return 0;
}
This is an exercise I've been stuck on for a while and am not sure how to approach, I keep getting this error for line 20 - source.c(20):
Warning C4244: 'function': conversion from 'int' to 'float', possible loss of data.
This is p_array[k] = (powf(2, k));
.
I have no clue how to fix this.
Any help would be greatly appreciated.