Found 33676 Articles for Programming

Haskell Program to Swap Two Numbers

Potti Chandra Sekhar sai
Updated on 14-Dec-2022 12:13:51

1K+ Views

This tutorial discusses writing a program to swap two numbers in the Haskell programming language. Variables are immutable in Haskell i.e once declared their values cannot be changed. So we cannot swap the values of two variables, but we can mimic this by swapping values in a list and tuple. In this tutorial we see, Program to swap two numbers in a binary tuple. Program to swap two numbers in a list. In Haskell, tuples are used to store elements of different data types as a collection. Tuples are identified by parenthesis at the ends. Tuples support only ... Read More

C++ Program to Convert List to Set

Arnab Chakraborty
Updated on 14-Dec-2022 12:11:53

2K+ Views

Lists in C++ are containers the same as vectors, but list implementation is based on doubly linked lists compared to the array implementation of vectors. Lists generally do not contain elements in contiguous locations, the elements of a list are distributed throughout the memory. Lists offer the same constant time operations anywhere in it, that is the main feature of using lists. Sets on the other hand are containers that contain unique values of a certain type and all the elements are sorted in ascending order. The two containers are different, but there are various ways to convert a list ... Read More

Haskell Program to determine the name and version of the operating system

Potti Chandra Sekhar sai
Updated on 14-Dec-2022 12:10:33

231 Views

This tutorial discusses writing a program to find the operating system info in the Haskell programming language. Haskell provides functions to find the system info. These functions can be accessed by importing the Info module from the System package in Haskell. In this tutorial, we see Program to display the name of the Operating System. Program to display the architecture of the processor. Program to display the compiler name. Program to display the compiler version. Syntax To import a module in Haskell the syntax is to follow. import packageName.moduleName To import the Info module from the system ... Read More

C++ Program to Print X Star Pattern

Arnab Chakraborty
Updated on 14-Dec-2022 12:09:10

4K+ Views

Displaying star patterns in different shapes, like pyramids, squares, and diamonds, is a common part of basic programming and logic development. We faced various problems involving stars and numerical patterns as we studied looping statements in programming. This article will demonstrate how to print an X or a cross using stars. We will see two methods for the same. First one is little bit complicated but the next method is much efficient. X Star Pattern (Using two sets of blank spaces) * * * * * ... Read More

C++ Program to Print Hollow Right Triangle Star Pattern

Arnab Chakraborty
Updated on 14-Dec-2022 12:06:16

1K+ Views

Displaying star patterns in different formats like pyramids, squares, and diamonds is very common in fundamental programming and logic building. We have seen several stars and number pattern problems while learning looping statements in programming. In this article, we will see how to print a hollow right triangle star pattern in C++. In this program, we take the line number n this will create a star pattern for n number of lines. Let us see the example for the same. Hollow Right Star Pattern * ... Read More

Haskell Program To Perform nCr (r-combinations)

Potti Chandra Sekhar sai
Updated on 14-Dec-2022 12:06:48

448 Views

This tutorial discusses writing a program to perform nCr combinations in the Haskell programming language. The nCr is used to find the number of ways r items can be selected from n items given that order doesn’t matter. The nCr is defined as n! / ( r! (n-r)! ). For example number of ways in which 3 items can be selected from 5 items is 5! / ( 3! (5-3)! ), i.e 10 ways. In this tutorial we see, Program to find the factorial of a number (helper function to find the nCr combinations). Program to find the ... Read More

How to Get Value from HashTable Collection in C# using Specified Key

Shilpa Nadkarni
Updated on 22-Dec-2022 18:09:47

7K+ Views

A hashtable is a collection of key−value pairs. We can access key−value pairs using an iterator. We can also access the keys of the hashtable in a collection. Similarly, we can access the values in a hashtable. Given a hashtable, it is also possible to access the value of a specified key or matching key of a specified value. Let’s discuss how we can access a value from the hashtable collection given a key. How to Get Value from Hashtable Collection using Specified Key? Here, we have to obtain a value from the key−value pair of hashtables when a ... Read More

Haskell Program to Find the Perimeter of a Circle

Potti Chandra Sekhar sai
Updated on 14-Dec-2022 12:00:56

367 Views

This tutorial discusses writing a program to find the perimeter of a circle in the Haskell programming language. The perimeter of the circle is the length of the boundary of the circle. The perimeter of a circle is also called the circumference. The perimeter of a circle is defined as 2*pi*r where r is the radius of the circle. For example area of the circle with a radius of 4 units is 25.13274 (2*pi*4). In this tutorial, we see two ways to implement a program to find the perimeter of a circle. Program to find the perimeter of ... Read More

How to get keys from a HashTable in C#?

Shilpa Nadkarni
Updated on 14-Dec-2022 12:04:46

415 Views

The HashTable is a non−generic collection in C#. It stores key−value pairs and is similar to a generic “Dictionary” collection. HashTable is defined in System.Collections.namespace. HashTable consists of key/value pairs in which each key is computed as a hash code and stored in a different bucket internally. Whenever the HashTable is accessed, this hash code is matched to the hash code of the specified key and thus the corresponding values are accessed. This mechanism optimizes the lookup in the HashTable. Let’s now discuss how to get keys from a HashTable in C#. How to Get Keys from a HashTable? ... Read More

Haskell Program to Find the Area of a Trapezium

Potti Chandra Sekhar sai
Updated on 14-Dec-2022 11:55:05

161 Views

This tutorial discusses writing a program to print the area of a trapezium in the Haskell programming language. A trapezium is a quadrilateral with one opposite side parallel. The above figure is a trapezium. The length of one of the parallel sides is denoted by a and the other side is denoted by b. The height of the trapezium is denoted by h. The area of a trapezium is defined as (a+b)/(2*h), where a and b are the lengths of the parallel sides and h is the height or distance between the parallel sides. In this tutorial, we see ... Read More

Advertisements