Found 7197 Articles for C++

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

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

779 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

C++ Program to convert Decimal Numbers to Octal

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

1K+ 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 that converts a decimal number into an octal number. Examples of decimal numbers and their corresponding octal numbers are as follows. ... Read More

C++ Program to Copy Strings

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

4K+ Views

In this article, we'll show how to write a C++ program to copy strings. A string in C++ is a sequence of characters, such as letters, numbers, symbols, or anything enclosed in double quotes (e.g., "Hello"). Copying a string means transferring all characters from one string to another or making an exact copy. For example, here's how copying works: Input: "Learning C++ is fun!" Output: "Learning C++ is fun!" (This is the copied string) We can copy a string in C++ using the following methods: Using strcpy() Function ... Read More

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

636 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

Advertisements