Vorheriges Thema anzeigen :: Nächstes Thema anzeigen |
Autor |
Nachricht |
Otacom
Anmeldungsdatum: 18.06.2006 Beiträge: 45
|
Verfasst am: 20.09.2008, 17:24 Titel: Sum & arithmetic mean in qbasic |
|
|
specification of a algorithm that having in input a vector of N
integers in providing output:
- sum of elements
- arithmetic means of vector
an example? thank ... |
|
Nach oben |
|
 |
MisterD

Anmeldungsdatum: 10.09.2004 Beiträge: 3071 Wohnort: bei Darmstadt
|
Verfasst am: 20.09.2008, 18:13 Titel: |
|
|
Code: | function sum(array() as integer, length as integer) as integer
dim n as integer
dim result as integer
for n = 0 to length-1
result=result+array(n)
next n
sum=result
end function
function avg(array() as integer, length as integer) as single
avg = sum(array,length) / length
end function |
something like that? _________________ "It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration."
Edsger W. Dijkstra |
|
Nach oben |
|
 |
Otacom
Anmeldungsdatum: 18.06.2006 Beiträge: 45
|
Verfasst am: 20.09.2008, 18:47 Titel: |
|
|
MisterD hat Folgendes geschrieben: | Code: | function sum(array() as integer, length as integer) as integer
dim n as integer
dim result as integer
for n = 0 to length-1
result=result+array(n)
next n
sum=result
end function
function avg(array() as integer, length as integer) as single
avg = sum(array,length) / length
end function |
something like that? |
ok, is it modular form? |
|
Nach oben |
|
 |
MisterD

Anmeldungsdatum: 10.09.2004 Beiträge: 3071 Wohnort: bei Darmstadt
|
Verfasst am: 20.09.2008, 20:13 Titel: |
|
|
what do you mean by modular form? its two functions, sum is totally isolated and avg uses sum, no other requirements. _________________ "It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration."
Edsger W. Dijkstra |
|
Nach oben |
|
 |
Elektronix
Anmeldungsdatum: 29.06.2006 Beiträge: 742
|
Verfasst am: 20.09.2008, 23:52 Titel: |
|
|
Perhaps when you post your question in
http://www.freebasic.net/forum/
you would get more answers, because they have no problems with answering in english.
 _________________ Und die Grundgebihr is aa scho drin- DOS is jo nett. |
|
Nach oben |
|
 |
Otacom
Anmeldungsdatum: 18.06.2006 Beiträge: 45
|
Verfasst am: 22.09.2008, 21:02 Titel: |
|
|
Ok ...
OT: what is modular form? An example? |
|
Nach oben |
|
 |
|