c ++负平方根

编程入门 行业动态 更新时间:2024-10-18 08:37:09
本文介绍了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 ++负平方根

本文发布于:2023-11-28 21:10:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1643964.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:平方根

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!