A is an integer and A>1. Write a simple program to solve the following problem.
1+2+3+...+N=?
Can you figure this one out?
Printable View
A is an integer and A>1. Write a simple program to solve the following problem.
1+2+3+...+N=?
Can you figure this one out?
Phew - my first VB code in a while :)Code:Dim sum As Long, n As Integer
sum = 0.5 * n * (n+1)
John
OK John, 1 + 4 + 9 + ... + N^2?
Had to think about that one a bit more...Code:Dim sum As Long, n As Integer
sum = (2 * n + 1) * (n + 1) * n / 6
John
So if N is 5...
1+2+3+4+5 = 55 ?
Can someone explain this to me?
Plus where does "A" come into it?
That was a misprint on my part A is the same as N or N should have been A
A is an integer A>1:
1+2+3+...+A=?
you can use A or N; whatever letter you like; sorry!!!
Well, someone is getting their homework done for free.
Hehe; this is not homework; trying to share a question from a job interview and sadly I don't get homework anymore -- I just have to write programs all day at work!!! :)
here's what i got:
A=0
if N=3
for next loop
A=A+N
There are 8 balls of equal size, but there is one ball that is the heaviest, find the heaviest ball by weighing them just twice in the weighing scale.
If you watch Zoom from Disney, then this question might seem trivial.
OK, Put 3 balls on one side of the scales and 3 on the other, if they weigh the same then take the 2 unweighed balls and put one on each side of the scales the heavier one is the heavy ball.
If they didn't weigh the same take the 3 balls from the heavy side and compare 2 of them, If one is heavier then that's the heavy ball, if not the third is the heavy one.
you should have said 9 balls, that makes it less obvious.
Uhm.. first you say that A>1 and then you say that A=0 in your code-example, don't you mean A=>0 or perhaps A=>1?
Actually I was using A as the counter going back to using N as the problem so I meant
N is an integer, N>1 so I need two variables one is a counter and one is a sum
A=0 ' Assign the counter to 0
N=3' Need to get sum
I like this as an answer better:
Dim Total as integer
Total=0 ' start counter off at 0
For I= 1 to N
Total=Total+I
Next I
Print Total