小编Lef*_*oon的帖子

C#math语句在部分工作时不起作用

我想知道这是否可能是某种相关性问题,因为当我在纸上做问题时,我得到了正确答案,但是当我运行代码时,我一直在反复尝试4.这是代码.为什么这些不平等?我错过了什么?

整个问题(每次迭代返回4):

for (int x = 1; x <= stackCount; x++) {
            temp = ((x - 1) / stackCount * uBound) + lBound + 1;
            Base[x] = Top[x] = Convert.ToInt32(Math.Floor(temp));
        }
Run Code Online (Sandbox Code Playgroud)

碎成碎片(正确运行):

double temp, temp1, temp2, temp3, temp4;
        for (int x = 1; x <= stackCount; x++) {
            temp1 = (x - 1);
            temp2 = temp1 / stackCount;
            temp3 = temp2 * uBound;
            temp4 = temp3 + lBound + 1;
            Base[x] = Top[x] = Convert.ToInt32(Math.Floor(temp4));
        }
Run Code Online (Sandbox Code Playgroud)

补充:是的,对不起,我忘记了这些声明:

//the main memory …
Run Code Online (Sandbox Code Playgroud)

c# math

0
推荐指数
1
解决办法
55
查看次数

标签 统计

c# ×1

math ×1