Creative Code

main.c(구조체- 좌표) 본문

C Programming

main.c(구조체- 좌표)

빛하루 2023. 8. 4. 15:57

※main.c파일

#include <stdio.h>
#include "point.h"

int main(void)
{
	point Point;
	int x1;
	int y1;
	printf("점의 x좌표 : ");
	scanf("%d",&x1);
	printf("점의 y좌표 : ");
	scanf("%d",&y1);
	Point.x = x1;
	Point.y = y1;
	printPoint(&Point);
	getLength(&Point);
	return 0;	
}

※point.h파일

#ifndef POINT_H
#define POINT_H

typedef struct point {
	int x;
	int y;
}point;


void printPoint(const point *p);
void getLength(const point *q);

#endif

※point.c파일

#include <stdio.h>
#include <math.h>
#include "point.h"

void printPoint(const point *p)
{
	printf("좌표 : (%d,%d)\n",p->x,p->y);
}

void getLength(const point *q)
{
	double length = (double)(q->x) * (double)(q->x) + (double)(q->y) * (double)(q->y);
	length = (double)pow(length,0.5);
	printf("길이 : %f \n",length);
}

'C Programming' 카테고리의 다른 글

name.c( 문자열 포인터로 입력)  (0) 2023.08.07
name.c(scanf로 문자열 입력받기)  (0) 2023.08.07
main.c(date)  (0) 2023.08.04
main.c(구조체)  (0) 2023.08.04
main.c(serial함수)  (0) 2023.08.04