I have the following formula:
F = X / 1+4+9+16+....+n^2
How can I write a program in QBasic
that find the result of F
?
Thanks.
I have the following formula:
F = X / 1+4+9+16+....+n^2
How can I write a program in QBasic
that find the result of F
?
Thanks.
From this useful page, the sum of the squares of the first n natural numbers is:
So you just need to calculate:
F = X * 6 / (n * (n + 1) * (2 * n + 1))
A power multiplier:
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