二点間の角度
Posted: 2008年8月28日(木) 11:02
を、計算するプログラムを作る練習をしていたのですが、何故かしらコンパイラは通るのにいざ実行すると一つ目の座標のxを入力する段で『問題が発生したため終了します』とパソコンから言われて実行出来ません。これは僕のプログラムに欠陥があるからなのか、パソコンがおかしいのか、どちらなのでしょうか?とりあえず、以下がプログラムの内容です。
最近雷ばっかりでパソコンつけるの恐いです…
#include <stdio.h>
#include <math.h>
typedef struct{
double x;
double y;
}Pos;
int main(void){
Pos pos1, pos2;
double ta, rad, dir;
puts("座標を二つ入力してください");
printf("X1:"); scanf("%lf", pos1.x);
printf("Y1:"); scanf("%lf", pos1.y);
printf("X2:"); scanf("%lf", pos2.x);
printf("Y2:"); scanf("%lf", pos2.y);
ta = sqrt((pos1.y - pos2.y) * (pos1.y - pos2.y)) / sqrt((pos1.x - pos2.x) * (pos1.x - pos2.x));
rad = atan(ta);
dir = rad / (3.14159265358979 * 180.0);
printf("二点間の角度は%fです", dir);
return(0);
}
あと、角度の出し方自体も色々サイトを見ながら作ったのですが、不安なのでそちらのほうも出来ればお願いします。最近雷ばっかりでパソコンつけるの恐いです…