本文介绍了c ++负平方根的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的目标是如果平方根为负,则打印 *** 。但我不能想办法改变默认 nan 文本到 ***
for(int i = x1; i <= x2; i ++){ double y = sqrt(pow * i-500); if(y =?){ outFile< ***;所以,我应该在if语句中写什么来使它成为可能?或者有另一种方法检查y是否为nan然后打印 * 解决方案检查对平方根函数的负输入?
for(int i = x1; i < = x2; ++ i) { double x = pow(i,2)+ 3 * i-500; if(x< 0) { outFile< ***; } else { outFile< sqrt(x); } }
My goal is to print *** if the square root is negative. But I can't think of a way to change default nan text to ***
for(int i=x1;i<=x2;i++){ double y = sqrt(pow(i,2)+3*i-500); if(y = ?){ outFile << "***"; }So, what should I write in the if statement to make it possible? Or maybe there is another way to check if the y is nan then print *
解决方案How about checking for a negative input to the square root function?
for (int i = x1; i <= x2; ++i) { double x = pow(i, 2) + 3*i - 500; if (x < 0) { outFile << "***"; } else { outFile << sqrt(x); } }
更多推荐
c ++负平方根
发布评论