1 // Test1027-求方程的根.cpp: 定义控制台应用程序的入口点。 2 // 3 4 #include "stdafx.h" 5 #include6 int mark = 0; 7 float haha(int a, int b, int c) 8 { 9 float temp = b * b - 4 * a*c;10 if (temp < 0)11 {12 temp = -temp;13 mark = 1;14 }15 else16 {17 mark = 0;18 }19 return sqrt(temp);20 }21 22 int main()23 {24 int a, b, c;25 float result1,result2;26 scanf_s("%d %d %d", &a,&b,&c);27 float h1, h2;28 h1 = -(float)b / (float)(2 * a);29 float h3 = haha(a, b, c)/(2*a);30 31 if (mark == 0)32 {33 h1 = h1 + h3;34 h2 = h1 - h3;35 36 printf("x1=%.3f x2=%.3f", h1, h2);37 }38 else if (mark == 1)39 {40 printf("x1=%.3f+%.3fi ", h1, h3);41 printf("x2=%.3f-%.3fi ", h1, h3);42 }43 44 //printf("%.3f", result);45 return 0;46 }