C++ Articles - Page 691 of 719

C++ Program to Compute Determinant of a Matrix

Nishu Kumari
Updated on 20-May-2025 20:11:00

11K+ Views

The determinant of a square matrix can be computed using its element values. The determinant of a matrix A can be denoted as det(A) and it can be called the scaling factor of the linear transformation described by the matrix in geometry. An example of the determinant of a matrix is as follows. The matrix is: 3 1 2 7 The determinant of the above matrix: = 7*3 - 2*1 = 21 - 2 = 19 So, the determinant is 19. Steps to Compute Determinant of a Matrix We find the determinant using a method called recursive Laplace ... Read More

C++ Program to Check if a Matrix is Invertible

Nishu Kumari
Updated on 30-May-2025 18:04:19

420 Views

A matrix is invertible if it has an inverse. An inverse of a matrix exists only when its determinant is non-zero. If the determinant of a matrix is zero, the matrix is called singular and cannot be inverted. In this article, we'll write a C++ program to check if a matrix is invertible using its determinant. To better understand this, let's take the following 3x3 matrix as an example: Given 3*3 Matrix: 4 2 1 2 1 1 9 3 2 To check if this matrix is invertible, we ... Read More

C++ Program to Multiply two Matrices by Passing Matrix to Function

Ankith Reddy
Updated on 24-Jun-2020 09:55:04

2K+ 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*4 matrix has 3 rows and 4 columns as shown below.8 6 3 5 7 1 9 2 5 1 9 8A program that multiplies two matrices by passing the matrices to functions is as follows.Example Live Demo#include using namespace std; void MatrixMultiplication(int a[2][3],int b[3][3]) {    int product[10][10], r1=2, c1=3, r2=3, c2=3, i, j, k;    if (c1 != r2) {       cout

C++ Program to Store and Display Information Using Structure

Nishu Kumari
Updated on 16-May-2025 19:14:01

8K+ Views

A structure is a collection of items of different data types. It is very useful in creating complex data structures with different data type records. A structure is defined with the struct keyword. In this article, we will store and display information of an employee using a structure. An example of a structure is as follows: struct employee { int empID; char name[50]; int salary; char department[50]; }; Store Information in Structure and Display It In this program, we store and display employee information using a ... Read More

C++ Program to Calculate Standard Deviation

Nishu Kumari
Updated on 21-May-2025 09:46:51

9K+ Views

Standard deviation is a measure of how spread out the numbers in a dataset are. It is the square root of the variance, where variance is the average of the squared differences from the mean. In this article, we will show you how to calculate the standard deviation in C++. Let's understand this with an example: Input: Numbers are 4, 8, 6, 5, 8 Calculating: Find the mean = (4 + 8 + 6 + 5 + 8) / 5 = 31 / 5 = 6.2 Subtract the mean and square the result: (4 - 6.2)^2 = ... Read More

C++ Program to Check if it is a Sparse Matrix

Nishu Kumari
Updated on 16-May-2025 19:14:48

796 Views

What is Sparse Matrix?A sparse matrix is a matrix in which the majority of the elements are zero. In other words, if more than half of the elements in a matrix are 0, it is called a sparse matrix. In this article, we will show you how to write a C++ program to check whether a given matrix is sparse or not. Let's understand this with an example. The matrix shown below contains 5 zeros. Since the number of zeros is more than half of the total elements (9), it is a sparse matrix: 1 0 2 5 0 ... Read More

C++ Program to Perform Matrix Multiplication

Nishu Kumari
Updated on 16-May-2025 18:37:23

10K+ Views

A matrix is a rectangular array of numbers arranged in rows and columns. To multiply two matrices, We multiply each row of the first matrix by each column of the second matrix and add the results to get a new matrix. An example of the multiplication of two matrices is as follow: Steps for Matrix Multiplication To multiply the matrices, we use pointers in C++, which means we directly access the elements through their memory addresses to read and calculate the values. Below are the steps we took: We first define the number ... Read More

C++ Program to Find Factorial of a Number using Recursion

Arjun Thakur
Updated on 24-Jun-2020 09:42:22

15K+ Views

Factorial of a non-negative integer n is the product of all the positive integers that are less than or equal to n.For example: The factorial of 4 is 24.4! = 4 * 3 * 2 *1 4! = 24The factorial of an integer can be found using a recursive program or an iterative program.The following program demonstrates a recursive program to find the factorial of a number −Example Live Demo#include using namespace std; int fact(int n) {    if ((n==0)||(n==1))    return 1;    else    return n*fact(n-1); } int main() {    int n = 4;    cout

C++ Program to Find Factorial of a Number using Iteration

Nishu Kumari
Updated on 15-May-2025 19:46:02

4K+ Views

In this article, we'll show you how to write a C++ program to find the factorial of a number using an iterative approach. The factorial of a number is the result of multiplying all the positive integers from 1 to that number. It is written as n! and is commonly used in mathematics and programming. Let's understand this with a few examples: //Example 1 Input: 5 The factorial of 5 is: 5 * 4 * 3 * 2 * 1 = 120 Output: 120 //Example 2 Input: 6 The factorial of 6 is: 6 * 5 * 4 ... Read More

C++ Program to Find the Frequency of a Character in a String

Nishu Kumari
Updated on 19-Aug-2025 17:13:23

18K+ Views

A string is a sequence of characters like letters, numbers, symbols, or anything enclosed in double quotes (e.g., "Hello"). Our goal is to find the frequency of a character in a given string, which means counting how many times that specific character appears in the string. Let's look at an example to understand the problem clearly- //Example 1 Input: String: "Tutorialspoint" Character to check: 't' Output: The character 't' appears 3 times in the string. //Example 2 Input: String: "Welcome to Tutorialspoint" Character to check: 'o' Output: The character 'o' appears 4 times in the string. ... Read More

Advertisements