
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 33676 Articles for Programming

3K+ Views
In Haskell we have isEven, isOdd and mod functions that can be used for checking whether a given number is even or odd. In the first example, we are going to use (isEven 0 = True and isEven n = isOdd (n - 1)) and (isOdd 0 = False and isOdd n = isEven (n - 1)) function. And in the second example, we are going to use (isEven n = n `mod` 2 == 0) function. Method 1: Checking whether a number is even or odd using isEven and isOdd function In this method, the isEven and isOdd functions ... Read More

216 Views
In Haskel we can use recursion along with helper function toconvert the Binary number to Gray code. In the first example, we are going to use base case, (grayCode "" = "" and grayCode [x] = [x]) and recursive case, grayCode (x:y:xs) = x : grayCode (xs ++ [if x == y then '0' else if x == '0' then '1' else '0'])). Where as in the second example, we are going to use two helper functions along with recursion. Method 1: Converting the Binary number to Gray Code using recursion In this method, the grayCode function is defined to ... Read More

348 Views
In Haskell, we will convert the decimal number to binary by using recursion and tail-recursion. In the first example, we are going to use base case, (decToBin 0 = "0" and decToBin 1 = "1") and recursive case, (decToBin n = decToBin (n `div` 2) ++ show (n `mod` 2)). Whereas in second example, we are going to use tail-recursive function. Algorithm Step 1 − The user defined, decToBin function is defined with base and recursive case as, Example 1 and 2 − decToBin 0 = "0" decToBin 1 = "1" decToBin n = decToBin ... Read More

773 Views
In Haskell, we can find the the GCD of two given numbers by using recursion along with gcd function and tail-recursion. In the first and second examples, we are going to use base case, (gcd a 0 = a) and recursive case, gcd a b = gcd b (a `mod` b)) and in the third example, we are going to use tail-recursive function. In the following examples we define a gcd function that takes two Int arguments a and b. The function uses pattern matching to handle two cases − If b is 0, the function returns a ... Read More

177 Views
In Haskell, we will find the the LCM of two given numbers by using recursion along with gcd and max function. In the first example, we are going to use (gcd) and (lcmOfTwoNumbers) function and in the second example, we are going to use (lcm) and (lcmOfTwoNumbers a b = lcm a b (max a b)) function. Algorithm Step 1 − The Prelude library is imported for hiding the gcd function. Step 2 − Define two user-defined functions - gcd and lcmOfTwoNumbers , Step 3 − Program execution will be started from main function. The main() function has whole ... Read More

2K+ Views
In Haskell, we can find the given number is PRIME or not by using recursion along with helper function. In the first example, we are going to use (isPrime n | n Bool isPrime n | n Integer -> Bool isPrimeHelper n d | d > (n `div` 2) = True | n `mod` d == 0 = False | otherwise = isPrimeHelper n (d + 1) main :: IO () main = do let ... Read More

495 Views
In Haskell, we can find reverse of a given number by using recursion along with helper function. In the first example, we are going to use (reverseNumHelper n rev) function and in the second example, we are going to use (reverseNum n | n < 10 = n| otherwise = (n `mod` 10) * (10 ^ numDigits (n `div` 10)) + reverseNum (n `div` 10)) function. Finding the reverse of a given number using recursion using the helper function In this method, the reverseNumHelper function takes two arguments: n and rev. n is the number to reverse and rev is ... Read More

893 Views
In Go programming language, a hash collection contains a hashmap which stores the values as key:value pairs for the efficient execution of the programs. In this article we will use two examples to get the hash collection values as an array. In the first example, we will create a slice and append the strings of map in that slice, in the second example we will hash the string and store it inside the map. In this way we will print the array. Syntax func make ([] type, size, capacity) The make function in go language is used to create ... Read More

139 Views
In Golang we have inbuild function like ok idiom to check whether a given key exist in hash collection or not. Hashmap is a collection of values paired with key in hashmap collection. In this article, we will create a hashmap using the built-in function then we will use ok idiom that returns true false value to check whether a key exists in the map or not. In this way a success or failure statement will be printed. Algorithm Create a package main and declare fmt(format package) in the program where main produces executable codes and fmt helps in ... Read More

379 Views
In golang we can merge two hash collection by using map function. A hashmap is present in hash collections. It stores key:value pairs. We can perform various operations on a hashmap like merging them. In this article we will merge two hashmaps using a method. In that method, we will create an additional map to store the merged key:value pairs. Then, the map will be printed on the terminal using fmt package. Algorithm Create a package main and declare fmt(format package) in the program where main produces executable codes and fmt helps in formatting input and output. ... Read More