Found 33676 Articles for Programming

C++ Program to Concatenate Two Strings

Nishu Kumari
Updated on 22-May-2025 19:14:17

1K+ Views

In this article, we'll show how to write a C++ program to concatenate two strings. A string in C++ is a sequence of characters like letters, numbers, symbols, or anything enclosed in double quotes (e.g., "Hello"). Concatenating two strings means joining them together to form one combined string. For example, if we have two strings: str1 = "Welcome to" and str2 = "tutorialspoint!", after concatenation, the result will be: result = "Welcome to tutorialspoint!". Approaches to Concatenate Strings in C++ We can concatenate strings in C++ using different methods. Below are the approaches we will cover: ... Read More

C++ program to Reverse a Sentence Using Recursion

Nishu Kumari
Updated on 15-May-2025 19:44:29

2K+ Views

In this article, we will write a C++ program to reverse a sentence using recursion. Reversing a sentence means changing the order of all its characters in each word, so the first character moves to the end, the last character comes to the front, and the middle characters follow in the opposite order. Let's understand this with an example: // Example 1 Input: Welcome to tutorialspoint! // After reversing the sentence Output: !tniopslairotut ot emocleW // Example 2 Input: Learning C++ with tutorialspoint is fun // After reversing the sentence Output: nuf si tniopslairotut htiw ++C gninraeL ... Read More

C++ Program to convert Octal Number to Decimal and vice-versa

Nishu Kumari
Updated on 20-May-2025 20:09:25

651 Views

In a computer system, the octal number is expressed in the octal numeral system while the decimal number is in the decimal numeral system. The octal number is in base 8 while the decimal number is in base 10. In this article, we will write a C++ program to convert an octal number to a decimal number and vice-versa. Here are some examples showing decimal numbers and their corresponding octal values: ... Read More

C++ Program to Access Elements of an Array Using Pointer

Nishu Kumari
Updated on 15-May-2025 19:45:32

14K+ Views

In this article, we'll show you how to write a C++ program to access elements of an array using pointer. A pointer is a variable that holds the memory address of another variable, allowing us to reference it directly. In other words, pointers point to a memory location and obtaining the value stored at that location is called dereferencing the pointer. By using pointers, we can access and work with array elements through their memory addresses. Let's look at a simple example: Input: An array: [10, 20, 30, 40, 50] // We'll use a pointer to access ... Read More

C++ Program to Find the Length of a String

Nishu Kumari
Updated on 22-May-2025 19:14:47

3K+ Views

In this article, we will show you how to find the length of a string in C++. A string in C++ is a sequence of characters, such as letters, numbers, symbols, or anything enclosed in double quotes (e.g., "Hello"). To find the length of a string, we count all the characters, including spaces, but we don't count the null terminator('\0'). For example, let's look at the following string in C++. // Example 1 Input: "Learning C++ with tutorialspoint is fun!" To find the length, we count every character, including spaces. So, the total length is 40. Output: 40 ... Read More

C++ Program to Find Transpose of a Matrix

Nishu Kumari
Updated on 16-May-2025 18:36:52

14K+ Views

A matrix is a rectangular array of numbers arranged in rows and columns. To find the transpose of a matrix, we arrange the rows of the original matrix as columns in a new matrix. Similarly, the columns can also be arranged as rows. An example of the transpose of a matrix is as follows: Finding Transpose of a Matrix To find the transpose of a matrix in C++, we use multidimensional arrays to store matrix values in rows and columns. Then, we swap the rows and columns to get the transpose. Below are the steps we followed: ... Read More

C++ Program to Multiply Two Matrix Using Multi-dimensional Arrays

Samual Sam
Updated on 24-Jun-2020 08:02:07

5K+ Views

A matrix is a rectangular array of numbers that is arranged in the form of rows and columns.An example of a matrix is as follows.A 3*3 matrix has 3 rows and 3 columns as shown below −8 6 3 7 1 9 5 1 9A program that multiplies two matrices using multidimensional arrays is as follows.Example Live Demo#include using namespace std; int main() {    int product[10][10], r1=2, c1=3, r2=3, c2=3, i, j, k;    int a[2][3] = { {2, 4, 1} , {2, 3, 9} };    int b[3][3] = { {1, 2, 3} , {3, 6, 1} , {2, 9, 7} };    if (c1 != r2) {       cout

C++ Program to Add Two Matrix Using Multi-dimensional Arrays

Nishu Kumari
Updated on 15-May-2025 19:42:23

2K+ Views

A matrix is a rectangular array of numbers arranged in rows and columns. To add two matrices, they must be the same size. We add each number in the first matrix to the number in the same position in the second matrix to get a new matrix An example of the addition of two matrices is as follow: Adding Two Matrices Using Multidimensional Arrays To add two matrices in C++, we use multidimensional arrays. These arrays help us store matrix values in rows and columns, just like a real matrix. Then, we add the two matrices stored ... Read More

C++ Program to Calculate Average of Numbers Using Arrays

Nishu Kumari
Updated on 13-May-2025 17:10:42

8K+ Views

An array stores multiple values of the same data type. To find the average, we add all the numbers and then divide the total by how many numbers there are. In this article, we'll show you how to write a C++ program to calculate the average of numbers using an array.  For example, if we have the numbers 40, 80, 10, 75, and 25, their total is 230, and the average is 230 / 5 = 46. Approaches for Calculating Average Using Arrays In C++, we can calculate the average of numbers in an array in two main ... Read More

C++ Program to Calculate Power Using Recursion

Nishu Kumari
Updated on 13-May-2025 17:12:30

5K+ Views

Calculating a power means multiplying the base by itself as many times as the exponent indicates. In this article, we'll show you how to write a C++ program to calculate the power of a number using recursion.  For example, 2 raised to the power of 3 (2^3) means multiplying 2 by itself 3 times: 2 * 2 * 2, which gives 8. Using Recursion to Calculate Power To calculate the power of a number, we use recursion, where a function keeps calling itself with smaller values until it reaches a stopping point. Here are the steps we ... Read More

Advertisements