Gambas/Maths

Back to Gambas

The Cross Sum Program
This miniprogram calculates the cross sum of an integer. You need 2 textboxes and 1 commandbutton to get the program going.

Please beware of the signs / and \. In this program the sign \ is used for a division without a remainder.

The Code

Addy The Sum Program
This miniprogram calculates the sum of a row of integers. You need 1 textarea, 1 textbox and 1 commandbutton to get the program going. You can also add negative integers. Very helpful is the Split command and the String array String[]

The Code

The Average Program
This miniprogram calculates the average of a row of integers. You need 1.textarea, 2 textboxes and 1 commandbutton to get the program going.

The Code

The Median
The Median of a list of values lies between two equal parts of the list. 50% of the values ar greater or equal to the median. 50% are smaller or equal to the median. In contrary to the average the median is not influenced that much by extreme values.

If you want to program the median, you have to xmedian = x[(n+1)/2] xmedian = 1/2*(x[n/2] + x[n/2+1])
 * 1.sort your list of values
 * 2.check if the list has an even or an odd number of values.
 * 3.choose the right formula for the median.
 * for an odd number of values
 * for an even number of values

example 1:

sorted list of values: 11 12 13 14 15   The number of values is odd. n = 5 (n+1)/2 = 6/2 = 3 xmedian = x[3] = 13

example 2.

sorted list of values: 11 12 13 14 15 16 The number of values is even, n = 6 n/2 = 6/2 = 3 x[3] = 13 x[4] = 14 xmedian = 1/2*(13+14) = 13,5

You can take the list from above and copy it into the Gambas median program. Use the clipboard of your computer for that. Ctrl+C = Copy, Ctrl + V = Paste

example program

You need 2 textareas, 3 commandbuttons and 1 textbox, to get the program going: