How to Find the Sum of odd numbers from 0 to 100 in F# ?

Recently , I started learning F# as hobby and started writing some simple programs . Today , I was trying out a sample program in F# which finds out the sum of odd numbers from 0 to 100 in F#.

How to Find the Sum of odd numbers from 0 to 100 in F# ?

Below is a sample code snippet that does the work.

// Ginktage - F# Program to find the sum of odd numbers from 0 to 100
open System
[<EntryPoint>]
let main argv = 
    let mutable sum = 0
    for indexer=0 to 100 do
        if indexer%2 <> 0 then 
            sum <- sum + indexer
    printfn "Sum is %A" sum
     // Printing the entered input
    let retval = Console.ReadLine()
    0 // return an integer exit code

image

If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

One Response

  1. Anthony August 3, 2014 Reply

Leave a Reply


x

Interesting BlogPosts to read

How to quickly remove multiple line breaks in Excel using VBA code?
There are times when you might copy few data from different source and you would end up getting unne...
How to change orientation of the worksheets in Microsoft Excel ?
This blog post will show the steps that are needed to change the orientation of the current workshee...
How to hide page breaks in worksheets in Microsoft Excel ?
When the page breaks is used to adjust the print area in a worksheet in excel , this would show up a...