问题
C++ code:
cout << "Roots are complex and different." << endl;
cout << "x1 = " << realPart << "+" << imaginaryPart << "i" << endl;
cout << "x2 = " << realPart << "-" << imaginaryPart << "i" << endl;
How can I convert this to Turbo C like printf
instead of cout
?
回答1:
May be you are seeking for this:
printf("Roots are complex and different.\n");
printf("x1 = %lf+%lfi\n",realPart,imaginaryPart);
printf("x2 = %lf-%lfi\n",realPart,imaginaryPart);
if realPart
and imaginaryPart
variables are in data type double
.
Use %f
for float
, %d
for int
, %s
for string
instead of %lf
in the code otherwise.
来源:https://stackoverflow.com/questions/32664533/how-to-convert-this-c-code-to-turbo-c