Simplicity
Simplicity

Reputation: 48986

QBasic - How to get the value of F

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.

Upvotes: 2

Views: 205

Answers (3)

DavidM
DavidM

Reputation: 21

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

Upvotes: 2

eoredson
eoredson

Reputation: 1165

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

Upvotes: 1

Paul R
Paul R

Reputation: 213200

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))

Upvotes: 2

Related Questions