Found 33676 Articles for Programming

Check if the String formed by the first and last X characters of a String is a Palindrome

Aishwarya Mani Tripathi
Updated on 08-Sep-2023 17:27:15

157 Views

In this tutorial, we will explore a problem statement that involves checking whether a string, formed by combining the first X characters and the last X characters of a given string, is a palindrome or not. A palindrome refers to a sequence of characters that remain unchanged when reading both forwards and backwards. The task is to determine if the resulting combined string, derived from the specified characters at the beginning and end of the original string, exhibits palindrome properties. To accomplish this, we will delve into an effective solution using the C++ programming language. By breaking ... Read More

Check if a given pattern exists in a given string or not including wild cards * and .

Aishwarya Mani Tripathi
Updated on 08-Sep-2023 17:31:18

283 Views

Check if a given pattern exists in a given string or not including wild cards * and . is a common problem in computer science and programming. In this problem, we are given a string (text) and a pattern, which can contain wildcard characters '*' and '.', and we need to check if the pattern matches the text or not. This problem is encountered in a wide range of applications, such as search engines, file systems, and network protocols. In this tutorial, we will discuss a simple and efficient solution to this problem using C++. We will start ... Read More

Check if a permutation of S2 can be obtained by adding or removing characters from S1

Aishwarya Mani Tripathi
Updated on 08-Sep-2023 16:51:05

118 Views

Checking if a permutation of S2 can be obtained by adding or removing characters from S1 is a common problem in computer science. This problem is of great significance in various domains, including data processing, text analysis, and pattern recognition. In this tutorial, we will be presenting a solution to this problem using C++ programming language. The approach involves analyzing the characteristics of S1 and S2 to establish whether S2 can be rearranged to form a permutation of S1. We will be providing the C++ code for this approach along with explanations to help readers understand the problem ... Read More

Tech number in Swift

Ankita Saini
Updated on 08-Sep-2023 15:59:09

199 Views

If the given number contains an even number of digits and the digits of the number can be divided into two equal parts from the middle. After dividing the digits sum up the divided digits and find the square of the final sum. If the square is equal to the sum itself then the given number is a tech number otherwise not. Example Demonstration Input 3025 Output Yes the given number is a tech number Input 2341 Output No the given number is not a tech number Here, 3025 is a ... Read More

Swift Program to Print Floyd’s Triangle

Ankita Saini
Updated on 08-Sep-2023 15:56:06

313 Views

Floyd triangle is right angle triangled which is named after Rober Floyd. It is created with the help of natural numbers starting from 1 in the top left corner and then the consecutive numbers are filled in the specified rows. Example Demonstration Input 4 Output 1 2 3 4 5 6 7 8 9 10 Here, the size of Floyd’s triangle is 4. So it will print Floyd’s triangle until 4 rows. In Swift, we can print Floyd’s triangle using the following methods: Using for−in loop Using while loop Using recursive function Algorithm ... Read More

How to Write Calculator Program using Switch Case in Swift

Ankita Saini
Updated on 08-Sep-2023 15:51:06

991 Views

A Calculator is an electronic device which is used to perform different types of mathematical operations like subtraction, addition, division, multiplication, etc. We can also create a calculator using Switch case and simple arithmetic operations in Swift programming. It will also perform the same mathematical operations as the original calculator. Example Demonstration Enter any two numbers: Number 1: 43 Number 2: 234 SIMPLE CALCULATOR 1. Addition 2. Subtraction 3. Multiplication 4. Division 5. Percentage Choose (1/2/3/4/5): 2 Result = -191.0 Here, we first enter the numbers on which we want to perform the ... Read More

How to Swap Pair of Characters in Swift?

Ankita Saini
Updated on 08-Sep-2023 15:35:03

534 Views

Swapping pair of characters is a process of interchanging the position of two characters in the given string. This operation is commonly used in various programming languages and applications to manipulate data. Example Input “mumbai” Output umbmia Input “Prita” Output rPtia Here, we divide the given string into a pair of characters like “mumbai”: “mu”, “mb”, “ai”. Now we swap the positions of the characters: “um”, “bm”, and “ia” and create the resultant string: “umbmia”. Similarly for input 2. In Swift, we can swap the pair of characters present in the given ... Read More

How to Calculate the Volume of a Tetrahedron in Swift?

Ankita Saini
Updated on 08-Sep-2023 15:30:27

144 Views

Tetrahedron is a triangular base pyramid. It is a platonic solid with four triangular faces, six straight edges and four vertex corners. Where each vertex is connected with every other vertex and each face is of an equilateral triangle. In Swift, we can calculate the volume of a tetrahedron using the following formula: Formula $$\mathrm{Area=(x*x*x*\sqrt{2})/12}$$ Here, x represents the sides of the tetrahedron. Algorithm Step 1 − Create a function which takes the side of the tetrahedron as a parameter and returns the volume. Step 2 − Inside the function, we use the mathematical formula to find the volume ... Read More

How to Calculate the Value of nPr in Swift?

Ankita Saini
Updated on 08-Sep-2023 18:37:42

161 Views

nPr is known as n permutation r, where n represents the total numbers and r represents the arrangement of the elements. A permutation is known as the arrangement of elements in a specified order. Elements can arrange either in a sequence or in a linear order, for example, we have a set of elements [2, 4], so the permutation is: [4, 2], [2, 4]. In permutation the order of elements matters whereas in combination the order of the elements does not matters. We can calculate the value of nPr with the help of the following formula: Formula nPr = ... Read More

How to Calculate the Area of a Tetrahedron in Swift?

Ankita Saini
Updated on 08-Sep-2023 15:04:47

97 Views

Tetrahedron is a 3−D triangular pyramid shape whose base is also a triangle. Generally, a tetrahedron contains four equilateral triangles, hence it has interior angles of 60 degrees. In Swift, we can calculate the area of a tetrahedron using the following formula: Formula $$\mathrm{Area=\sqrt{3}*X*X}$$ Here, x represents the side of the tetrahedron. If you wish to find the area of one side of a tetrahedron then you can use the following formula: Formula $$\mathrm{Area\:of\:one\:side\:of\:tetrahedron =(\sqrt{3}*y*y)/4}$$ Here, y represents the side of the tetrahedron. Algorithm Step 1 − Create a function which takes the side of the tetrahedron ... Read More

Advertisements