1. 程式人生 > >第16周 點結構體1.0

第16周 點結構體1.0

問題:

請編寫程式,輸入一點的橫縱座標,輸出該點到原點的距離

#include <stdio.h>
#include <stdlib.h>
#include<math.h>
struct Point
{
    float x;  //橫座標
    float y;  //縱座標
};

int main()
{   struct Point p;
    float l;
    printf("請輸入p1點的座標:");
    scanf("%f %f",&p.x ,&p.y);
    l=sqrt((p.x*p.x)+(p.y*p.y));
    printf("p1點到原點的距離為:%f\n",l);
    return 0;
}