C语言初学结构体,不太懂错哪了
查看原帖
C语言初学结构体,不太懂错哪了
919727
Loving_coding楼主2023/1/13 02:39
#include<stdio.h>
#include<math.h>

int main(){
int i,j;
float dis1=0,dis2=0,dis=0;
    struct point{
        int  x, y;
    };
    point p[3] = 
    { 
    {scanf("%f%f",&p[0].x,&p[0].y)},
    {scanf("%f%f",&p[1].x,&p[1].y)},
    {scanf("%f%f",&p[2].x,&p[2].y)} 
    };
    for (i = 0; i <= 1; i++) {
        dis1 =dis1+ sqrt(pow(p[i].x-p[i + 1].x, 2)+ pow(p[i].y - p[i + 1].y, 2));
    }
    for (j = 0; j < 1; j++) {
        dis2  = sqrt(pow(p[j].x - p[j + 2].x, 2) + pow(p[j].y - p[j + 2].y, 2));
    }
    
    dis = dis1 + dis2;
    printf("%f", &dis);
    return 0;
}
2023/1/13 02:39
加载中...