ここで宿題をしようとしています。これは、特定の数のポイントの (0,0) までの距離を示すプログラムを作成することです。ただし、何らかの理由で、プログラムが起動するとすぐに、Windows は動作を停止したと表示します。2 つの異なるコンパイラで試しましたが、エラー メッセージは表示されません。
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
struct point {
int x;
int y;
};
struct point getPoint();
void printPoint(struct point);
double distanceToO(struct point p);
void createArray(struct point, int);
int main() {
int number, i;
struct point coord[number];
printf("Type the number of points you want to create: ");
scanf("%d", &number);
printf("\n\n");
for(i=0;i<number;i++)
coord[i]=getPoint();
printf("\n\t\tPoint\tDistance to (0,0)\n");
for(i=0;i<number;i++) {
printPoint(coord[i]);
printf("\t%0.2lf", distanceToO(coord[i]));
}
system("pause");
return 0;
}
struct point getPoint() {
struct point p;
printf("Type the x and the y-value for a point with a space in between: ");
scanf("%d %d", &p.x, &p.y);
return p;
}
void printPoint(struct point p){
printf("\n\t\t(%d,%d)",p.x,p.y);
}
double distanceToO(struct point p) {
return sqrt((0-p.x)*(0-p.x)+(0-p.y)*(0-p.y));
}
それが詳細に行うべきことです:
最初にいくつのポイントを作成する必要があるかを尋ね、次にユーザーにポイントの x 値と y 値を尋ねるプログラムを作成します。次に、プログラムは、ポイントと (0,0) までの距離を示すテーブルを提供する必要があります。次の関数を作成/使用する必要があります: "point getpoint()" - 座標の入力を要求します "void printpoint(point p)" - ポイントの座標を出力します "double distanceToO(point p)" - を返しますdistance to (0,0) ポイントの x 座標と y 座標の 2 つのメンバーを持つ構造ポイントを作成します。
誰かが何が悪いのかヒントを教えてもらえますか?