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 330 of 2650
5K+ Views
In this problem, we simply need to divide two integers without using multiplication, division and mod operator. Though we can use addition or multiplication or bit manipulation. The problem statement states that we will be given two integers x and y. Without using multiplication, division or mod operator, we need to determine the quotient after dividing x by y. Example INPUT: x=15 , y=5 OUTPUT: 3 INPUT: x=10 , y=4 OUTPUT: 2 INPUT: x=-20 , y=3 OUTPUT: -6 Approach Approach-1(using simple mathematics) In this approach, we will use a simple mathematics algorithm. Below is the step-by-step illustration of the ... Read More
245 Views
A figurative number that depicts a dodecagon is called a dodecagonal number. The Centered Dodecagonal number is represented by a dot in the centre and other dots encircling it in the successive dodecagonal (i.e. a 12-sided polygon) layers. Centered Dodecagonal number can be better explained with the below figure. For n=1, only a single dot will be there in the centre. So the output will be 1. For n=2, a single dot in the centre followed by a dodecagon encircling it. Thus, the total number of dots will be 13. So the next centred dodecagonal number ... Read More
324 Views
In Haskell, we can display Prime Numbers between Two Intervals using user-defined functions and list comprehension. In the first example, we are going to use (isPrime and primesInRange) user-defined functions and in the second example, we are going to use list comprehension. Algorithm Step 1 − The Data.List library is imported. Step 2 − The user-defined isPrime function is defined. Step 3 − Program execution will be started from main function. The main() function has whole control of the program. Step 4 − The variables named, “lower” and “upper” are being initialized. It will hold the range between which ... Read More
186 Views
In Haskell, we can useuser-defined functions and using recursion. In the first example we are going to use (user-defined, isArmstrong and armstrongInRange) function and in the second example, we are going to use recursion with base and recursive case. Algorithm Step 1 − The user-defined isArmstrong function is defined 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. Step 3 − The variables named, “lower” and “upper” are being initialized. It will hold the range between which the armstrong numbers ... Read More
216 Views
In Haskell, we can Display Prime Numbers Between Intervals using user-defined function along with filter function and recursion. In the first example we are going to use user-defined, (isPrime) function with (primeInRange a b = filter isPrime [a..b] ) function and in the second example, we are going to use recursion with base and recursive case. Algorithm Step 1 − The Data.List library is imported. Step 2 − The user-defined isPrime function is defined as, Step 3 − Program execution will be started from main function. The main() function has whole control of the program. It is written as ... Read More
983 Views
In this article we are going to learn how to make a simple calculator in Haskell using switch…case. In the first example, we are going to use case statements with different operators and in the second example, we are going to use map of functions as (fromList [('+', (+)), ('-', (-)), ('*', (*)), ('/', (/))]). Method 1: Program to make a simple calculator using case statement In this method, a simple calculator program in Haskell is formed which takes three arguments, x, op and y. The x and y are of type Double and op is of type Char. The ... Read More
822 Views
In Haskell, we can list comprehension, filter function and recursion to display factors of a number. In the first example we are going to use (factors n = [x | x n `mod` x == 0) [1..n]) function. And in third example, we are going to use recursion with base and recursive case. Algorithm Step 1 − The user-defined factors function is defined using internal functions. 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. Step 3 − The variable ... Read More
179 Views
Haskell has functions like higher order and filter, that can be used for getting the Armstrong number between two given internvals. In the first example we are going to use (isArmstrong and armstrongInRange function with higher order) and in the second example, we are going to use (filter isArmstrong [a..b]) function. Algorithm Step 1 − The user-defined isArmstrong function is defined. 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. Step 3 − The variables named, “lower” and “upper” are ... Read More
2K+ Views
In Haskell, we will compare numbers and strings using library function using compare, min and max functions. Also, by using Eq and Ord typeclasses. In the first example we are going to use (compare num1 num2 and compare str1 str2) function and in the second example, we are going to use (max num1 num2 and min str1 str2) function. And in third example, we are going to use (num1 == num2) function along with (num1 /= num2) typeclasses. Algorithm Step 1 − The Data.Ord library is imported, which contains the compare function. Step 2 − Program execution ... Read More
498 Views
Haskell has internal functions like divMod, mod and properFraction to get the remainder of the float number. In the first example we are going to use (divMod' (x) (y)) function and in the second example, we are going to use (mod' x y) function. And in third example, we are going to use (properFraction $ x / y) function. Algorithm Step 1 − The Data.Fixed module is imported to use divMod function. Step 2 − The variables named, “x” and “y” are being initialized. It will hold the floating point numbers whose remainder value is to be found ... Read More