English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

there are only 2 textboxes which are to be used . in the first textbox, the last number will be entered and on the second textbox, the output which is the sum of all the numbers (factorial) should be displayed.

2007-01-31 02:59:15 · 4 answers · asked by zerreanne 1 in Computers & Internet Programming & Design

4 answers

use a FOR/NEXT loop with the STEP argument to DECRIMENT the variable

Dim intCounter as integer

STATIC intSolution as Integer

FOR intCounter = 5 to 1 STEP -1

intSolution = (some calculation performed against intCounter)

Next intCounter

This is using VB-6 code, since you didn't specify a particular version of the laguage. Check http://www.pscode.com for great sample codes.

2007-01-31 07:28:48 · answer #1 · answered by Richard H 7 · 0 1

Did you mean to use the word SUM ? I'm not trying to be picky, but a factorial is not a sum.
A factorial is : 5! = 1 x 2 x 3 x 4 x 5 = 120 .
A sum is : 1 + 2 + 3 + 4 + 5 = 15.

in C ++ for example
you can assign a variable to the user's input of the number 5
then you can make a loop ----
while( whole_num > 1 )
{
total = total * whole_num;
whole_num = whole_num - 1;
}

I'm not sure how to write this in Visual Basic, but if you understand my logic here, you should be able to translate it into other languages.

2007-01-31 11:31:21 · answer #2 · answered by BIGDAWG 4 · 0 1

use double variables...

2007-01-31 11:09:27 · answer #3 · answered by aRnObIe 4 · 0 0

try vbcode.com

2007-01-31 11:08:15 · answer #4 · answered by noyonk 3 · 0 0

fedest.com, questions and answers