Menu



Manage

Study_C > 5-3.c Lines 30 | 859 바이트
다운로드

                        #define _CRT_SECURE_NO_WARNINGS // C4996 에러 제거를 위한 코드 (scanf 에러방지)
#include <stdio.h>              // 입-출력을 하기 위한 함수 stdio.h를 불러오기 (표준 입출력)
#include <stdlib.h>             // rand() 입력을 위한 라이브러리 불러오기
#include <time.h>               // time() 입력을 위한 time.h 불러오기
int get_line_parameter(int x1, int y1, int x2, int y2, float* slope, float* yintercept);

int main()
{
	float s = 0, y = 0;

	if (get_line_parameter(3, 3, 6, 6, &s, &y) == -1)
		printf("에러");
	else
		printf("기울기는 %f, y절편은 %f\n", s, y);

	return 0;
}

// 기울기와 y 절편을 계산
int get_line_parameter(int x1, int y1, int x2, int y2, float* slope, float* yintercept)
{
	if (x1 == x2)
		return -1;
	else
	{
		*slope = (float)(y2 - y1) / (float)(x2 - x1);
		*yintercept = y1 - (*slope) * x1;
		return 0;
	}
}