|
-
May 4th, 2000, 06:02 AM
#1
Thread Starter
Addicted Member
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?
-
May 4th, 2000, 06:23 AM
#2
Fanatic Member
Code:
Dim sum As Long, n As Integer
sum = 0.5 * n * (n+1)
Phew - my first VB code in a while 
John
-
May 4th, 2000, 07:16 AM
#3
Frenzied Member
OK John, 1 + 4 + 9 + ... + N^2?
-
May 5th, 2000, 12:24 AM
#4
Fanatic Member
Bring 'em on
Code:
Dim sum As Long, n As Integer
sum = (2 * n + 1) * (n + 1) * n / 6
Had to think about that one a bit more...
John
-
May 5th, 2000, 12:45 AM
#5
So if N is 5...
1+2+3+4+5 = 55 ?
Can someone explain this to me?
Plus where does "A" come into it?
-
May 5th, 2000, 01:01 AM
#6
Thread Starter
Addicted Member
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!!!
-
May 5th, 2000, 02:05 AM
#7
Addicted Member
Well, someone is getting their homework done for free.
-
May 5th, 2000, 02:09 AM
#8
Thread Starter
Addicted Member
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
-
May 5th, 2000, 09:56 AM
#9
an interview question: efficient design
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.
-
May 5th, 2000, 08:22 PM
#10
Frenzied Member
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.
-
May 7th, 2000, 12:06 AM
#11
New Member
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?
Well, it's a pentium parrot, besides, it's only a decimal.
-
May 7th, 2000, 02:36 AM
#12
Thread Starter
Addicted Member
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|