Visual F# 100 Examples: Example 8 to 10

Posted by Rey Dacoco in

Problem: Make a console application that will accept five numbers and display the sum.

open System
//change the title to Add Five Numbers
System.Console.Title<-"Add Five Numbers "
//change the foreground color to cyan
Console.ForegroundColor<-ConsoleColor.Cyan
printfn "\t\t\tEnter the first number:"
let intnum1=Convert.ToInt32(System.Console.ReadLine())
printfn "\t\t\tEnter the second number:"
let intnum2=Convert.ToInt32(System.Console.ReadLine())
printfn "\t\t\tEnter the third number:"
let intnum3=Convert.ToInt32(System.Console.ReadLine())
printfn "\t\t\tEnter the fourth number:"
let intnum4=Convert.ToInt32(System.Console.ReadLine())
printfn "\t\t\tEnter the fifth number:"
let intnum5=Convert.ToInt32(System.Console.ReadLine())
let  intsum=intnum1+ intnum2 + intnum3 + intnum4 + intnum5
printfn "\t\t\tThe sum is:%i" intsum

Problem: Make a console application that will ask the power transmitted and power received then display the power loss value.
open System
//change the title to Calculate Power Loss
System.Console.Title<-"Calculate Power Loss "
//change the foreground color to cyan
Console.ForegroundColor<-ConsoleColor.Cyan
printfn "\t\t\t\tPower transmitted:"
let dblpowertrans=Convert.ToDouble(System.Console.ReadLine())
printfn "\t\t\tPower recieved:"
let dblpowerrec=Convert.ToDouble(System.Console.ReadLine())
let dblpowerloss= dblpowertrans/ dblpowerrec
printfn "\t\t\t Power loss:%f " dblpowerloss

Problem: Develop a console application that will ask the base value and height value then display the volume of a pyramid.
open System
//change the title to Volume of a Pyramid
System.Console.Title<-" Volume of a Pyramid"
//change the foreground color to cyan
Console.ForegroundColor<-ConsoleColor.Cyan
printfn "\t\t\tBase value:"
let dblbase=Convert.ToDouble(System.Console.ReadLine())
printfn "\t\t\tHeight value:"
let dblheight=Convert.ToDouble(System.Console.ReadLine())
let  dblvolume=(dblbase*dblheight)/3.0
printfn "\t\t\tVolume of a pyramid:%f" dblvolume

0 comments

Post a Comment

Contributor

My photo
I am just a simple man with a simple mind. And this is my simple blog. New Posts will be available soon. Enjoy reading and never stop learning:)

Total Pageviews

Link List

Archives

Got questions? You can reach me here: