Found 7346 Articles for C++

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

C++ Program to Find the Normal and Trace

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

309 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

C++ Program to Copy All the Elements of One Array to Another Array

Arnab Chakraborty
Updated on 14-Dec-2022 12:22:48

3K+ Views

The array data structures are used to store homogeneous data in a consecutive memory location to access them in a sequential manner. Arrays are linear data structure so that the basic operations on array can be performed in linear time. In this article we will see how to copy elements from one array to another new array in C++. The new array will be of same type since array elements are homogeneous. After creating another array of same size, we simply copy the elements from first array to the second one by one. Let us see the algorithm and the ... Read More

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

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

9K+ 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

2K+ 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

C++ Program to Convert Set of String to Array of String

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

2K+ Views

Sets in C++ re containers that contain unique values of a specific type. Arrays or the array container in std C++ is a fixed-size container that contains elements of a specific size. Arrays are like vectors, but the main difference is that arrays are of a fixed size whereas vectors can be dynamic. The array container in C++ is a wrapper for the standard arrays that are available in both C and C++. There is a problem in this conversion though, std arrays do not have support for the common insertion methods that are available with the other containers. So, ... Read More

C++ Program to Convert List to Set

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

1K+ 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

C++ Program to Print X Star Pattern

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

3K+ 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

754 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

Advertisements