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
Server Side Programming Articles - Page 331 of 2650
306 Views
Haskell has internal functions like negate, abs and signum functions that can be used to get magnitude of the given number. In the first example we are going to use (negate n) function and in the second example, we are going to use (abs) function. In third example, we are going to use (signum x) function. Algorithm Step 1 − Define the magnitude function Step 2 − Program execution will be started from main function. The main() function has whole control of the program. Step 3 − The variable named, “num” is being initialized. It will hold the number ... Read More
253 Views
In Haskell, we can use denominator, div, quot and gcd functions to obtain the denominator from a rational number. In the first example we are going to use (denominator r) function and in the second example, we are going to use (d `div` gcd n d) function. Algorithm Step 1 − The Data.Ratio module is imported to use denominator function. Step 2 − Program execution will be started from main function. The main() function has whole control of the program. It is written as main = do. It calls the denominator function with the rational number and prints ... Read More
315 Views
In Haskell, we will convert boolean variables into string by using user-defined function, boolToString along with if-else statement and pattern matching. In the first example, we are going to use (boolToString b = show b) function and in the second example, we are going to use (boolToString b = if b then "yes" else "no"). And in third example, we are going to use pattern matching. Algorithm Step 1 − Define the boolToString function Step 2 − The program execution will be started from main function. The main() function has whole control of the program. It is written as ... Read More
328 Views
In Haskell, we can use internal functions like fromIntegral intToLong and toInteger function and toEnum to convert int type variable to long. In the first example, we are going to use (let longVar = fromIntegral intVar :: Int64) and in the second example, we are going to use (intToLong = toEnum) function. Algorithm Step 1 − The Data.Int module is imported. Step 2 − The program execution will be started from main function. The main() function has whole control of the program. Step 3 − The variable named, “intVar” is being initialized. It will hold the Int type variable ... Read More
362 Views
In Haskell, we can use fromIntegral function along with toInteger and truncate function, div and mod functions to convert long type variable into int. In the first example, we are going to use ( let intVar = fromIntegral longVar :: Int) and in the second example, we are going to use (let highPart = fromIntegral (longVar `div` 2^32) :: Int and let lowPart = fromIntegral (longVar `mod` 2^32) :: Int). Algorithm Step 1 − The program execution will be started from main function. The main() function has whole control of the program. It is written as main ... Read More
2K+ Views
In Haskell, we will convert int type variables to char by using user-defined function using chr function, toEnum function and list indexing. In the first example, we are going to use (intToChar I | i >= 0 && i = 0 && i = 0 && i = 0 && i Maybe Char intToChar i | i >= 0 && i putStrLn $ "The character value is " ++ [c] ++ "." Nothing -> putStrLn "Invalid input. Please enter an integer between 0 and 255." Output The character ... Read More
1K+ Views
In Haskell, we can use pattern matching, digitToInt, reads and a user-defined functions to convert char-type variables to int. In the first example, we are going to use cases for matching the pattern and in the second example, we are going to use (charToInt c = if isDigit c then Just (digitToInt c) else Nothing). And in third example, we are going to use (charToInt c = case reads [c] of [(x, "")] -> Just x and _ -> Nothing) function. Algorithm Step 1 − The internal function is defined Step 2 − Program execution will be started ... Read More
321 Views
In Haskell, we can use the user-defined function, Folder, reverse and helper function to convert binary to octal number. In the first example, we are going to use (binaryToOctal binary = showOct decimalValue "" where decimalValue = foldl (\acc x -> acc * 2 + digitToInt x) 0 binary) function. In the second example, we are going to use (binaryToOctal binary = showOct decimalValue "" where decimalValue = foldl (\acc x -> acc * 2 + digitToInt x) 0 binary octalDigits = reverse (octalHelper decimalValue) octalHelper n | n < 8 = [n] | otherwise = (n `mod` 8) : ... Read More
545 Views
In Haskell, we can convert Boolean to String by using user-defined function along with guards and if-else statements. In the first example, we are going to use (boolToString True = "True" and boolToString False = "False") function and in the second example, we are going to use (boolToString b | b = "True" | otherwise = "False") as function definition. And in the third example, we are going to use (boolToString b = if b then "True" else "False"). Algorithm Step 1 − Define the Boolean function Step 2 − Program execution will be started from main function. ... Read More
865 Views
In Haskell, we can use functions like foldl, recursion, and list comprehension to convert a binary number to decimal. In the first example, we are going to use (binToDec = foldl (\acc x -> 2*acc + digitToInt x) 0) and in the second example, we are going to use base case, (binToDec "" = 0) and recursive case, (binToDec (x:xs) = 2 * binToDec xs + digitToInt x) function. And in the third example, we are going to use (binToDec = sum . zipWith (\x y -> 2^x * digitToInt y) [0..] . reverse). Algorithm Step 1 − ... Read More