C++ Programming Code Examples

C++ > Arrays and Matrices Code Examples

"Array index" starts with 0, which means the first array element is at index 0, second is at index 1 and so on. We use this information to display the array elements. See the C++ code

To achieve Addition of two matrix we need 2 "Dimensional Array" and add their elements with each other, print result on screen. Enter elements of firts matrix. Enter elements of 2.

String is a "sequence of characters". char data type is used to represent one single character in C++. So if you want to use a String in your program then you can use an "array of chars".

2 const variables row & col are used to define size. If we do not make both const then error found because without "const reserve word" they are behaving as variable. Before placing

In this program, user is asked to entered the number of rows r & columns c. The value of r & c should be less than 100 in this program. Then, the program adds these two matrices,

Takes n number of element from user (where, n is specified by user), stores data in an array and calculates the average of those numbers, program calculates the average if the number

A C++ function to find the factorial of a given number using matrix multiplication method. Assigning numbers from "1 to n" to the super diagonal indexes of the matrix and assigning

Array is the collection of similar data type, In this c++ program we find duplicate elements from an array, Suppose array have 3, 5, 6, 11, 5 and 7 elements, in this array 5 appear two

"Partitioning the array" on the basis of values at high as pivot value. Swapping value at high and at the index obtained. Partitioning array using last element as a pivot. And recursively

To find the "Largest Element", the first two elements of array are checked and largest of these two element is placed in arr[0]. Then, the first and third elements are checked and

Learn to "multiply two matrices" and display it using user defined function. This program asks user to enter the size of the matrix (rows and columns). Then, it asks the user to enter

In this program, "enter the size "of 2 matrix at first. To multiply two matrices, the number of columns of first matrix should be equal to the "number of rows" to second matrix. C++ Code

You have to ask to the user to enter array size array elements to store all the array elements in one dimensional and then print the array in "one dimension" using one for loop as shown
3D array contains three for loops. to initialize and "print three dimensional" array, you have to use three for loops. Third for loop forms 1D array, Second for loop forms 2D array and the
"Two dimensional" (2D) array can be made in C++ Language by using two for loops, first is outer for loop and the second one is inner for loop. Outer for Loop is responsible for rows
To "delete element" from an array in C++, you have to first ask to the user to enter the array size then ask to enter the array element, ask to enter the element which is "to be deleted".
Enter the array size and array elements, now start finding for the "smallest element" in the array to display the smallest element of the array as shown here in C++ sample program.
Enter array size, array elements, element to be insert, enter the index where to insert the desired element in the array, so this program insert the desired element and displaying the
Program ask to the user to enter array 1 and 2 size, then ask to enter array 1 and 2 elements, to "merge or add" to form new array, display the result of the added array or merged array
To reverse an array in C++ programming, you have to ask to the user to enter the array size and array elements. Now start swapping the array elements. Make a variable say temp of
Program ask to the user to enter any two 3*3 array elements to subtract them i.e., Matrix1 - Matrix2, then display the "subtracted" result of the two matrices ( Matrix3 ) on the screen:
To transpose any matrix in C++ Programming language, you have to first ask to the user to enter the matrix and "replace row" by column and column by row to "transpose" that matrix
To find the largest element in an array in C++ programming, enter the array size, enter the array elements. Start finding for the Largest element in the array to "Display the Largest"
First we have to clear about what is transpose of a matrix. Its to replace the number of rows with number of colums, vice versa to make a new matrix. So for example if a matrix 'A' has
Program declare an integer array of size five, initialize it using for loop. Pass size and array name to function. Function uses for loop and "swap array elements" with in it. A for loop is

Page 1 Page 2