QBasic - 如何获得F的值

时间:2012-12-06 12:25:24

标签: formula qbasic

我有以下公式:

F =  X / 1+4+9+16+....+n^2

如何在QBasic中编写一个找到F结果的程序?

感谢。

3 个答案:

答案 0 :(得分:2)

this useful page开始,前n个自然数的平方和为:

sum of the squares of the first n natural numbers

所以你只需要计算:

F = X * 6 / (n * (n + 1) * (2 * n + 1))

答案 1 :(得分:1)

CLS
INPUT "Input the value of n: ", n%
INPUT "The value of X: ", X
denominator% = 0
FOR i% = 1 TO n%
    denominator% = denominator% + i% ^ 2
NEXT i%
F = X / denominator%
PRINT "F = "; F

答案 2 :(得分:0)

功率倍增器:

DEFDBL A-Z
INPUT "Input the value of n: ", n
INPUT "The value of X: ", X
INPUT "The power: ", p
denominator = 0
FOR i = 1 TO n
    denominator = denominator + i ^ p
NEXT
F = X / denominator
PRINT "F = "; F
END