Programming/C++

[C] Struct distance example

OKOK 2017. 3. 28. 18:54

/*------------------------------------------------------------------------------------------

@ Pratice C laguage


Author           : SAM

Created          : 28-03-2017

Modified         : 28-03-2017

Language/ver     : C in MSVS2015


Description     : Practice : distance1.c

------------------------------------------------------------------------------------------*/


#include <stdio.h>

#include <math.h>


struct point {

int x;

int y;

};


int main(void) {

struct point p1, p2;

double distance;


fputs("Input first x, y ", stdout);

scanf_s("%d %d", &p1.x, &p1.y);


fputs("Input first x, y ", stdout);

scanf_s("%d %d", &p2.x, &p2.y);


/*Calculate distance between p1 and p2*/


distance = sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));

printf("Distance between two points is %f\n", distance);



return 0;

}




오랜만에 하니까 include, .h fputs, scanf_s 등의 단어들이 생소하다 ㅠㅠ 매일 한시간씩만 투자하자.