sqrt 的顶部和底部数字
Top and bottom numbers of sqrt
所以我被困住了,或者我把自己与以下内容混淆了:我需要使用 for 循环来计算正整数平方根的顶部和底部数字
即:
Enter Num: 10
Top is 4
Bottom is 3
Enter Num: 16
Top is 4
Bottom is 3
Enter Num: 8
Top is 3
Bottom 2
编辑:
我有
for(int top =1;top >=num; top++)
top >=num
去那里吗?我知道10^(1/2)
是3.16
还有顶部和底部是如何找到的?我不知道 sqrt(10) 顶部和底部是 4 和 3...这是分数还是简化的平方?我对这个问题感到困惑。
基于这里的帮助是答案
for(int top = 1; top <=num ; top++)
{
if( top * top >= num)
{
cout << "Top is " << top ;
cout << "nBottom is " << (top-1) << endl;
top =num +1;
}
}
你可以只循环整数,直到你传递平方根:
int bottom = 0;
int top = 0;
for (int i = 1; i <= num; ++i) {
if (i * i > num) {
top = i;
break;
}
bottom = i;
}
相关文章:
- 比较并显示使用最小值(a,b)和最大值(a、b)升序排列的4个数字
- 为什么随机数生成器不在void函数中随机化数字,而在main函数中随机化
- 检查输入是否不是整数或数字
- 如何(从固定列表中)选择一个数字序列,该序列将与目标数字相加
- 如何用数字处理log(0)
- 最高有效数字侧的第N位
- 如何获取一个数字的前3位
- 查找最接近的大于当前数字的数字的索引
- 找到两对数字,使它们的乘积的绝对差最小化
- 我想做一个彼此不同但重复出现的数字
- 将数字转换为字母(例如:123 转换为一二三)
- C++如何计算用户输入的数字中的偶数位数
- 如何在C++中确定文本文件中的元素是字符还是数字
- 打印数字图案
- C++问题:用户认为数字1-100,程序提出问题不超过6次即可得到答案。无法正确
- 如何检查一个c++字符串中有多少相同的字符/数字
- 求出有多少个数字是完美平方,而sqrt()是L,R范围内的素数
- 将数字打印成文字
- 当使用比格式支持的精度更高的精度来显示数字时,会写出什么数据
- sqrt 的顶部和底部数字