我想在这里写作业,写一个程序,显示距离(0,0)的某些点数。然而由于某种原因,一旦我的程序启动,windows就说它已停止工作。我用两种不同的编译器试了一下,他们不给我任何错误信息。我的C程序已经停止工作
#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) “ - 将距离返回到(0,0) 创建一个结构点,该点具有两个成员的x坐标和点的y坐标。
有人可以告诉我什么是错的?
你试图调试它? – 2013-03-06 13:43:30
我注意到的第一件事是这行:'struct point coord [number];'你正在尝试使用尚未初始化的数字创建一个数组。 – jonhopkins 2013-03-06 13:43:58
您应该在编译器上启用警告,例如使用gcc:-Wall -Wextra – hyde 2013-03-06 13:59:49