I'm learning the basics of C right now. I am trying to input data into an array. After some trial and error, I've found that I can do what I need to using a float array as opposed to a double array.
#include <stdio.h>
int main()
{
float x[4]={2.2,3.3,4.4,5.5};
scanf("%f",&x[3]);
printf("%f",x[3]);
return 0;
}
The user input 3
would result in 3.000000
However in this version:
#include <stdio.h>
int main()
{
double x[4]={2.2,3.3,4.4,5.5};
scanf("%f",&x[3]);
printf("%f",x[3]);
return 0;
}
The user input 3
would result in 5.500001
Why is this, and how can I properly enter values to/print out the array values?