F# Recipe #1 – Display Odd Numbers between 0 and 100 in Console Window

Problem

You need to write a F# program to display odd numbers between 0 and 100 in the console window.

F# Program to display odd numbers between 0 and 100 in the Console Window.

open System
[<EntryPoint>]
let main argv = 
    let mutable sum = 0
    for index=0 to 100 do
        if index%2 <> 0 then 
            sum <- sum + index
    printfn "sum is %A" sum
    let ret = Console.ReadLine()
    0//

Output

sum is 2500

Share:

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

In this post, you’ll learn about the error message “FileOpenAccessDenied – You do not have permissions to open this file...
  • .NET
  • December 3, 2024
You might have had a situation where your code once worked fine in ASP.NET application but now throws the below...
  • .NET
  • December 3, 2024
C# uses the flower bracket “{” and “}” to identify the block or scope of the function or program ....
  • .NET
  • December 3, 2024