2

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.

Simplicity
  • 47,404
  • 98
  • 256
  • 385

3 Answers3

2

From this useful page, the sum of the squares of the first n natural numbers is:

sum of the squares of the first n natural numbers

So you just need to calculate:

F = X * 6 / (n * (n + 1) * (2 * n + 1))
Paul R
  • 208,748
  • 37
  • 389
  • 560
2
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
eoredson
  • 1,167
  • 2
  • 14
  • 29
DavidM
  • 21
  • 1
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
eoredson
  • 1,167
  • 2
  • 14
  • 29