본문 바로가기
C언어

[C언어] 포인터를 이용하여 두 수의 실근을 구하는 함수를 작성하시오 void quadratic (int a, int b, int c, double* xplus, double* xminus)

by 이얏호이야호 2022. 12. 14.

공부하시는대에 도움이 됐으면 좋겠습니다.

답안코드 확인해주세요!

 

더보기
include <stdio.h>
#include <math.h>

void quadratic (int a, int b, int c, double* xplus, double* xminus)
{
	*xminus  = (-b - sqrt (b * b - 4 * a * c))/ (2 * a);
	*xplus  = (-b + sqrt (b * b - 4 * a * c))/ (2 * a);
}

int main (void)
{
	int a = 10, b = 40, c = 30;
	double xplus, xminus;

	quadratic (a, b, c, &xplus, &xminus);
	
	printf ("첫번째 실근: %lf\n", xplus);
	printf ("두번째 실근 %lf\n", xminus);
	return (0);
}


더 많은 C코드가 보고 싶다면?

https://chuinggun.tistory.com/category/C%EC%96%B8%EC%96%B4

댓글