Skip to content
This repository has been archived by the owner on Jul 10, 2024. It is now read-only.

Commit

Permalink
Resolved issue: Write a F# program to print diamond pattern #3543 (#4783
Browse files Browse the repository at this point in the history
)

* Add files via upload

* Add files via upload

* Delete program/program/print-diamond-pattern/PrintDiamondPattern.fs

* resolved issue 3543

---------

Co-authored-by: Yuri Cunha <me@yuricunha.com>
Co-authored-by: Harsh Raj <harshraj8843@gmail.com>
  • Loading branch information
3 people authored Dec 1, 2023
1 parent e12b6dc commit 2d970f9
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions program/program/print-diamond-pattern/PrintDiamondPattern.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
let printDiamond n =
// Function to print a single line of the diamond
let printLine i =
let stars = new string('*', i * 2 - 1)
let spaces = new string(' ', n - i)
printfn "%s%s" spaces stars

// Upper half of the diamond
for i in 1 .. n do
printLine i

// Lower half of the diamond
for i in n - 1 .. -1 .. 1 do
printLine i

// Take the size of the diamond from the user
printfn "Enter the size of the diamond: "
let size = System.Console.ReadLine() |> int

// Print the diamond
printDiamond size

1 comment on commit 2d970f9

@vercel
Copy link

@vercel vercel bot commented on 2d970f9 Dec 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.