Found 33676 Articles for Programming

Haskell Program to read the height of a person and the print person is taller, dwarf, or average height person

Akhil Sharma
Updated on 23-Jan-2023 11:31:38

154 Views

This tutorial will help us in reading the height of a person and printing if the person is taller, dwarf or average height person on being compared. The height value (in centimeters) is passed as argument to the function defined and then the height is being compared with the condition defined in Haskell. And the final output is displayed. Algorithm Step 1 − Program execution will be started from main function. The main() function has whole control of the program. Step 2 − Create user defined function to perform the task Step 3 − The if-else statement is defined ... Read More

Haskell Program to extract the last two digits from the given year

Akhil Sharma
Updated on 23-Jan-2023 11:16:52

476 Views

This tutorial will help us in extracting the last two digits from the given year. The year value is passed as an argument to the function defined and then the last two digits are extracted by using various methods in Haskell. And the final output is displayed. For example, For entered year = 2023, the last two digits = 23. Algorithm Step 1 − The Data.Char module is imported to use digitToInt function. Step 2 − The extractLastTwoDigits function is defined Step 3 − Program execution will be started from main function. The main() function has whole control of ... Read More

Haskell Program to read coordinate points and determine its quadrant

Akhil Sharma
Updated on 23-Jan-2023 11:14:11

277 Views

This tutorial will help us in reading the x and y coordinates and determine its quadrant. If both the coordinates are positive, the point lies in first quadrant; if x coordinate is positive and y coordinate is negative, the point lies in fourth quadrant ; if x coordinate is negative and y coordinate is positive, the point lies in second quadrant and if both the coordinates are negative, then point lies in third quadrant. Algorithm Step 1 − The quadrant function is defined using certain conditions on x and y coordinates. Step 2 − Program execution will be ... Read More

Haskell Program to calculate the volume and area of Sphere

Akhil Sharma
Updated on 23-Jan-2023 11:12:16

283 Views

This tutorial will help us in calculating the volume and area of Sphere. The volume of a sphere is a measure of the amount of space inside the sphere. And area involves the surface area of the sphere. Method 1: Using the User-defined Function In this method, we will see two examples where we have used user-defined function with different techniques. Algorithm Step 1 − The Text.Printf module is imported. Step 2 − The volume and area functions are defined on the basis of simple mathematical formula as volume r = (4.0 / 3.0) * pi * (r ^ ... Read More

Haskell Program to calculate the volume and area of Cone

Akhil Sharma
Updated on 23-Jan-2023 11:10:26

257 Views

This tutorial will help us in calculating the volume and area of the Cone. The volume of a cone is a measure of the amount of space inside the cone. And area involves the surface area of the cone that is obtained from the lateral area of a cone. The formula for the volume of a cone is V = (1/3) * π * r^2 * h, where r is the radius of the base of the cone, h is the height of the cone, and π is approximately equal to 3.14. And the formula for the surface area of ... Read More

Haskell Program to calculate the volume, diagonal, and area of Cuboids

Akhil Sharma
Updated on 23-Jan-2023 11:08:10

264 Views

This tutorial will help us in calculating the volume, diagonal, and area of the Cuboids. The volume of a cuboid is a measure of the amount of space inside the cuboid. And area involves the surface area of the cuboid. The diagonal of a cuboid is a line segment connecting two opposite vertices of the cuboid. It is also known as the "space diagonal" or "body diagonal" of the cuboid. Algorithm Step 1 − The volume, diagonal and area functions are defined on the basis of simple mathematical formula as volume l w h = l * w ... Read More

Haskell Program to calculate the volume and area of the Cylinder

Akhil Sharma
Updated on 23-Jan-2023 10:28:46

312 Views

This tutorial will help us in calculating the volume and area of the Cylinder. The volume of a cylinder is a measure of the amount of space inside the cylinder. The area involves the surface area of the cylinder. The formula for the volume of a cylinder is the product of the base area of the cylinder, which is given by πr^2 and the height h. The formula for the surface area of a cylinder is the sum of the areas of the two circular faces and the area of the rectangular lateral surface. Algorithm Step 1 − The ... Read More

Add a character to a specific position in a string using Python

Vikram Chiluka
Updated on 25-Aug-2023 00:51:31

67K+ Views

In this article, we will learn how to add a character to a specific position in a string in Python. Methods Used The following are the various methods to accomplish this task − Using the '+' operator Using join() function Using format() function Method 1: Using the '+' operator We can concatenate strings and characters using the symbol "+" at the required positions. Adding Character at the End of a String Algorithm: Following are the Algorithms/steps to be followed to perform the desired task. − Create a variable to store an input string. Use the "+" operator ... Read More

How utility types are used in TypeScript?

Shubham Vora
Updated on 20-Jan-2023 18:08:57

507 Views

TypeScript allows us to create a new type from the existing types, and we can use the utility types for such transformation. There are various utility types that exist in TypeScript, and we can use any utility type according to our requirements of the type transformation. In this tutorial, we will learn about the different utility types with examples. Partial Type in TypeScript The Partial utility type transforms all the properties of the current type to optional. The meaning of the partial is either all, some, or none. So, it makes all properties optional, and users can use it while ... Read More

How does tuple destructuring work in TypeScript?

Shubham Vora
Updated on 20-Jan-2023 18:04:48

2K+ Views

In TypeScript, a tuple is an object which contains the values of different data types. The length of a tuple is always pre-defined. It is similar to an array, but the array contains the values of only one data type, and the tuple contains values of multiple data types. Destructuring the tuple means getting the values from the tuple in separate variables. For example, we need to use tuple values multiple times in the code block. We can get all values in separate variables and use variables whenever we require tuple values, rather than every time accessing values from tuple ... Read More

Advertisements