I'm writing a C code with the idea create a function input numbers into 2 arrays(
Read_data) function. Then I will call it in the main function and print out those 2 arrays' elements. My relative code is as below:
#include<stdio.h>
#include<conio.h>
#include<math.h>
#define NUMBER 3
void Read_data(double* x, double* y)
{
for (int i = 0; i < NUMBER; i++)
{
printf_s("座標値xを入力してください:\n");
printf_s("x[%d]= ", i);
scanf_s("%3f", &x[i]);
}
for (int i = 0; i < NUMBER; i++)
{
printf_s("\n座標値xを入力してください:\n");
printf_s("y[%d]= ", i);
scanf_s("%3f", &y[i]);
}
}
int main()
{
double X[NUMBER], Y[NUMBER];
Read_data(X,Y);
for (int i = 0; i < NUMBER; i++)
{
printf("X[%d]= %f\n", i, X[i]);
}
for (int i = 0; i < NUMBER; i++)
{
printf("Y[%d]= %f\n", i, Y[i]);
}
But when I compiled it first I input the numbers and then it appears very strange numbers that I don't know what type of errors cause this.
I will text out those number because I can't paste the picture there
座標値xを入力してください:
x[0]= 5
座標値xを入力してください:
x[1]= 6
座標値xを入力してください:
x[2]= 7
座標値xを入力してください:
y[0]= 8
座標値xを入力してください:
y[1]= 3
座標値xを入力してください:
y[2]= 9
X[0]= -92559604497122534761720676471189149555955165722294310802554880.000000
X[1]= -92559604521067777587750189883038321855178746716337109586673664.000000
X[2]= -92559604545013020413779703294887494154402327710379908370792448.000000
Y[0]= -92559604568958263239809216706736666453625908704422707154911232.000000
Y[1]= -92559604425286806283632136235641632658284422740165914450198528.000000
Y[2]= -92559604580930884652823973412661252603237699201444106546970624.000000
What I have tried:
I have separated that Read_data() function into 2 functions each input 1 array but It still not work out.
If anyone can spot any problem in my code above then I will be very grateful!
Thank you!