Sum multiples of 3 and 5: Difference between revisions

From Rosetta Code
Content added Content deleted
Line 3: Line 3:
== {{header|BASIC}} ==
== {{header|BASIC}} ==
{{works with|FreeBASIC}}
{{works with|FreeBASIC}}
{{incorrect||(Or if the function is right, the output is wrong.)}}
<lang basic>
Declare function mulsum35(n as integer) as integer
<lang basic>Declare function mulsum35(n as integer) as integer
Function mulsum35(n as integer) as integer
Function mulsum35(n as integer) as integer
Dim s as integer
Dim s as integer
Line 16: Line 16:
Print mulsum35(1000)
Print mulsum35(1000)
Sleep
Sleep
End
End</lang>
{{out}}
</lang>
=== Output ===
467
467
=={{header|Perl 6}}==

Revision as of 15:55, 14 May 2013

Sum multiples of 3 and 5 is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.

The objective is to find the sum of multiplies of 3 or 5 below n within a function. Test it with n = 1000.

BASIC

Works with: FreeBASIC
This example is incorrect. Please fix the code and remove this message.

Details: (Or if the function is right, the output is wrong.)

<lang basic>Declare function mulsum35(n as integer) as integer Function mulsum35(n as integer) as integer

   Dim s as integer
   For i as integer = 1 to n
       If (i mod 3 = 0) or (i mod 5 = 0) then
           s += 1
       End if
   Next i
   Return s

End Function Print mulsum35(1000) Sleep End</lang>

Output:
 467

Perl 6