Akhil Sharma has Published 671 Articles

Golang Program to open a file in read-write mode with truncating file

Akhil Sharma

Akhil Sharma

Updated on 03-May-2023 09:46:31

144 Views

In Golang, the functions os.openfile () and ioutil.Writefile() are used to access/open a file in read-write mode without truncating it. In this article, we will understand the functionality of these two functions using two different methods. In the first method we will use the OpenFile() function present in os package ... Read More

Golang Program to open a file in write-only mode

Akhil Sharma

Akhil Sharma

Updated on 03-May-2023 09:44:13

2K+ Views

In Golang, we can use OS functions os.OpenFile(), os.Create() and ioutil.WriteFile to open a write-only file. Here we are going to see three different Examples to understand the functionality of these functions. In the first program we will use the OpenFile() function while in the second and third program, we ... Read More

Haskell Program to Check Armstrong Number

Akhil Sharma

Akhil Sharma

Updated on 25-Apr-2023 15:35:09

196 Views

In Haskell we can check whether a given number is Armstrong or not using list comprehension and sum function. Armstrong numbers, also known as narcissistic numbers, are numbers such that the sum of the cubes of their digits is equal to the number itself. For example, the number 153 is ... Read More

Haskell Program to Check Leap Year

Akhil Sharma

Akhil Sharma

Updated on 25-Apr-2023 15:34:14

376 Views

In Haskell, we can check whether a given year is a leap year is not using simple boolean expression. A leap year is a year that has an extra day (February 29th) compared to a normal year. For example, 2004 is a leap year. To determine if a year is ... Read More

Haskell Program to Convert Array to Set (HashSet)

Akhil Sharma

Akhil Sharma

Updated on 25-Apr-2023 15:26:36

134 Views

In Haskell, we will convert Array to Set (HashSet) by using fromList, nub and foldr functions. In the first example, we are going to use ( let set = Set.fromList arr) and in the second example, we are going to use ( let set = nub arr). And ... Read More

Haskell Program to Convert File to Byte Array

Akhil Sharma

Akhil Sharma

Updated on 25-Apr-2023 15:25:46

261 Views

In Haskell, we will convert File to byte array by using B.readFile function along with fromIntegral and foldl function. In the first example, we are going to use ( let byteArray = B.unpack bytes) and in the second example, we are going to use (let wordArray = map fromIntegral ... Read More

Haskell Program to convert primitive types to objects

Akhil Sharma

Akhil Sharma

Updated on 25-Apr-2023 15:12:55

134 Views

In Haskell, we will convert primitive types to objects by using accessor functions along with getName function, constructors and record syntax. In the first example, we are going to use (getName person = name person) and in the second example, we are going to use (getName (Person name _) = ... Read More

Haskell Program to Print Right Triangle Star Pattern

Akhil Sharma

Akhil Sharma

Updated on 24-Apr-2023 11:39:31

166 Views

In haskell we can use mapM, forM as well as recursive function to create a simple right triangle star pattern. What is a Right Triangle Star Pattern? A right triangle pattern is a series of asterisks or other characters arranged in a triangular shape. In the case of a right ... Read More

Haskell Program To Find The Perfect Number

Akhil Sharma

Akhil Sharma

Updated on 24-Apr-2023 11:37:54

239 Views

In haskell we can use list comprehension and brute-force method to find the perfect number. What is a Perfect Number? Perfect numbers are positive integers that are equal to the sum of their proper divisors. A divisor of a positive integer n is a positive integer that divides n exactly, ... Read More

Haskell Program to Check Whether a Number is Prime or Not

Akhil Sharma

Akhil Sharma

Updated on 24-Apr-2023 11:37:11

401 Views

To check whether a given number is prime or not we are going to use mod function and list comprehension method in Haskell. What is a Prime Number? A prime number is a positive integer greater than 1 that is only divisible by 1 and itself. In other words, a ... Read More

Advertisements