Programming Articles - Page 467 of 2896

C++ Program to Compute the Sum of Diagonals of a Matrix

Arnab Chakraborty
Updated on 14-Dec-2022 16:04:28

7K+ Views

The utilization of 2-dimensional arrays or matrices is extremely advantageous for several applications. Matrix rows and columns are used to hold numbers. We can define 2D matrices in C++ using multi-dimensional arrays as well. In this article, we'll look at how to use C++ to calculate the diagonal sum of a given square matrix. The matrices have two diagonals, the main diagonal and the secondary diagonal (sometimes referred to as major and minor diagonals). The major diagonal starts from the top-left corner (index [0, 0]) to the bottom-right corner (index [n-1, n-1]) where n is the order of the square ... Read More

C++ Program to Print first letter of each word using regex

Arnab Chakraborty
Updated on 14-Dec-2022 14:45:07

565 Views

A useful tool for string operations is regex. This may be found in virtually all high-level current programming languages, including C++. Regular expressions (Regex) are utilized as general-purpose search patterns. For instance, by constructing a straightforward string known as a regular expression, we may implement password validation logic with at least one capital, one lowercase, one number, one special character, and a total length of at least 8 characters. In this tutorial, we'll look at how to use C++ to display only the first letters of words included within a specified string. Here, we'll look at a sentence that uses ... Read More

C++ Program to Swapping Pair of Characters

Arnab Chakraborty
Updated on 14-Dec-2022 14:39:09

3K+ Views

A string is a group of characters. They can be described as character arrays as well. An array of characters can be thought of as strings, and each string has a set of indices and values. The switching of characters at two specified indices in a string is one of the modifications we can sometimes make to strings. In this article, we will see how to swap two characters in a string from two given indices using C++. Syntax char temp = String_variable[ ] String_variable[ ] = String_variable[ ] String_variable[ ] = temp Using indices, ... Read More

C++ Program to Replace a Character at a Specific Index

Arnab Chakraborty
Updated on 14-Dec-2022 14:37:16

2K+ Views

Strings are a collection of characters. We can also say them as character arrays. Considering an array of characters as strings, the strings have specified indices and values. Sometimes we can perform some modification on strings, one such modification is replacing characters by providing a specific index. In this article, we will see how to replace a character from a specific index inside a string using C++. Syntax String_variable[ ] = In C++ we can access the string characters using indices. Here to replace a character with some other character at a specified index, we simply ... Read More

C++ Program to Iterate Over an Array

Arnab Chakraborty
Updated on 14-Dec-2022 14:34:45

4K+ Views

Arrays are data of the same type stored in contiguous locations in memory. To access or address an array, we use the starting address of the array. Arrays have indexing, using which we can access the elements of the array. In this article, we take a look at methods to iterate over an array. This means accessing the elements that are present in an array. Using for loop The most common method of iterating over an array is using for loops. We use a for loop to iterate through an array in the next example. One thing is to be ... Read More

Haskell Program to Display Fibonacci Series

Potti Chandra Sekhar sai
Updated on 14-Dec-2022 13:56:06

3K+ Views

This tutorial discusses writing a program to display Fibonacci Series in the Haskell programming language. The Fibonacci series is a sequence in which each number is the sum of the preceding two terms. The Fibonacci series up to five terms is 0 1 1 2 3. In this tutorial we see, Program to print nth fibonacci number. Program to print the first ‘n’ terms in the Fibonacci series. Program to print the first ‘n’ terms in the Fibonacci series using the list comprehension. Program to print the first ‘n’ terms in the Fibonacci series using the map function. ... Read More

C++ Program to Find the Normal and Trace

Arnab Chakraborty
Updated on 14-Dec-2022 14:50:37

471 Views

2-Dimensional arrays or matrices are very much useful in several applications. Matrices have rows and columns and store numbers inside them. In C++ also we can define 2D matrices using multi-dimensional arrays. In this article, we will see how to calculate the Normal and the Trace of a given matrix using C++. The Normal is the square root of the sum of all elements present in the matrix. And the trace is the sum of elements present in the main diagonal. Let us see the algorithm and C++ code representation. Matrix Normal $\begin{bmatrix} 5 & 1& 8ewline 4 ... Read More

Haskell program to check whether the input number is a Prime number

Potti Chandra Sekhar sai
Updated on 14-Dec-2022 12:21:57

457 Views

This tutorial discusses writing a program to check whether the input number is a Prime number in the Haskell programming language. Haskell is a Declarative, Strongly Typed, and Functional programming Language. The computations in Haskell are mathematical functions. A prime number is a number having only 1 and the number itself as a factor. Note 1 is neither a prime nor a composite number because it has only one factor. For example, 3 is a prime number because it has only two factors 1 and the number 3 itself. In this tutorial we see, Program to check whether a ... Read More

C++ Program to Sort the Elements of an Array in Ascending Order

Arnab Chakraborty
Updated on 14-Dec-2022 12:21:17

13K+ Views

To solve some problems effectively, it's important to arrange the data items in the correct sequence. One of the most popular arranging problems is the element sorting problem. This article will demonstrate how to arrange array members in C++ in ascending order (according to rising values). To arrange either numerical or non-numerical elements in a specific order, a wide variety of sorting algorithms are available in this field. Only two straightforward sorting techniques will be covered in this article. the selection sort and the bubble sort. Let's examine each one individually using appropriate techniques and C++ implementation code. Sort array ... Read More

C++ Program to Sort the Elements of an Array in Descending Order

Arnab Chakraborty
Updated on 14-Dec-2022 12:18:13

3K+ Views

Arranging data items in a proper form is an essential task while solving some problems in an efficient way. The element sorting problem is one of the most commonly discussed arranging problem. In this article we will see how to arrange the array elements in descending order (decreasing order of their values) in C++. There are many different sorting algorithms present in this domain to sort numeric or nonnumeric elements in a given order. In this article we will see only two simple methods of sorting. The bubble sort and the selection sort. Let us see them one by one ... Read More

Advertisements