私はCプログラムを作っていました。 (私は初心者であり、プログラミングでは非常に新しいです)。私は最初の入力を求めてから、それを待たずに別の入力をタイプして、非常に速く終了します。私はeclipse-cdtとUbuntuを使用しています。cプログラムは入力を待っていません
コード
#include <stdio.h>
#include <stdlib.h>
int main(){
float x1,x2,x3,y3,y2,y1,slope12,slope23;
int exi;
printf("this program finds that three point are co-linear or not. you just have to enter the value of the x and y's\n");
printf("now enter the the value of x1 and y1 of point (x1,y2) here here resplectevely :- ");
scanf("%f%f",&x1,&y1);
printf("now enter the value of the x2 and y2 of point (x2,y2) here respectively here :- ");
scanf("%f%f",&x2,&y2);
printf("now enter the value of x3 and y3 of point (x3,y3) here respectively :- ");
scanf("%f%f",&x3,&y3);
slope12=(y1-y2)/(x1-x2);
slope23=(y2-y3)/(x2-x3);
if(slope12==slope23)
printf("\nthe points are co-liner and are in strait line");
else
printf("\nthe points are not in strait line and are not co-linear");
///delaying the program ending
printf("\nenter any digit to exit");
scanf("%d",&exi);
printf("you enterd %d good bye",exi);
return 0;
}
出力
[email protected]:/media/jos/D/c progs/eclipse/linux/coliner-points/Debug$ ./coliner-points
this program finds that three point are co-linear or not. you just have to enter the value of the x and y's
now enter the the value of x1 and y1 of point (x1,y2) here here resplectevely :- 7,8
now enter the value of the x2 and y2 of point (x2,y2) here respectively here :- now enter the value of x3 and y3 of point (x3,y3) here respectively :-
the points are not in strait line and are not co-linear
enter any digit to exityou enterd 0 good [email protected]:/media/jos/D/c progs/eclipse/linux/coliner-points/Debug$
私のコードで間違ったか、エラーが発生しています?
は、カンマを入力しないでください。あなたのscanfは数字の間のスペースを探しています。 –
私のために働く?それ以外の点は出力が間違っていることです(これは常にポイントが直線上にないことを示しています)。これはおそらく浮動小数点比較の結果になります。このリンクを使用すると改善できる可能性があります:http://faq.cprogramming。あなたの改行問題の修正として、com/cgi-bin/smartfaq.cgi?answer = 1352443831&id = 1043284392 –
@Scott Hunterありがとうございました –