當前位置:學識都>好好學習>考研>

實用C++面試筆試題目

學識都 人氣:1.97W

定義一結構體變量,用其表示點座標,並輸入兩點座標,求兩點之間的距離

實用C++面試筆試題目

解:#include

#include

struct point

{

float x;

float y;

};

main()

{ float dis;

struct point pt1,pt2;

printf(“input point1.x:”);

scanf(“%f”,&pt1.x);

printf(“input point1.y:”);

scanf(“%f”,&pt1.y);

printf(“input point2.x:”);

scanf(“%f”,&pt2.x);

printf(“input point2.y:”);

scanf(“%f”,&pt2.y);

dis=sqrt((pt1.x-pt2.x)*(pt1.x-pt2.x)+(pt1.y-pt2.y)*(pt1.y-pt2.y));

printf(“The distance of the two points is:%f”,dis);

}