이차방정식 근의 공식(by sqrt)

apircity·2022년 5월 3일
0

c study

목록 보기
1/3
post-thumbnail

📢 sqrt 함수?

  • #include<math.h>
  • double sqrt(double x)->x의 제곱근
#include<stdio.h>
#include<math.h>
int main()
{
double result;
result=sqrt(9.0);
printf("%lf", result); //3.000000 출력
return 0;
}

📌 how to solve

  • route=sqrt(b^2-4ac)
  • 근: (-b +- route) / (2 * a);
#include<stdio.h>
#include<math.h>
int main()
{
	double a = 0, b = 0, c = 0;
	double x1 = 0, x2 = 0;
	double route = 0;
	printf("세 정수를 입력하세요: ");
	scanf_s("%lf %lf %lf", &a, &b, &c);
	route = sqrt(b * b - 4 * a * c);
	x1 = (-b + route) / (2 * a);
	x2 = (-b - route) / (2 * a);
	printf("x1= %lf, x2= %lf", x1, x2);
	return 0;
}

🎉 후기

math.h의 수학 함수를 처음 써봤는 데 생각보다 다양한 함수가 있었고 다는 아니더라도 더 많은 함수를 다룰 수 있도록 노력해야겠다
처음 써보는거여서 그런지 코드가 난잡한 데 나중에 근이 없는 경우와 하나만 있는 경우 2개 있는 경우를 나눠서 출력할 수 있도록 코드를 한번 짜봐야겠다

profile
junior developer

0개의 댓글