Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C++ Articles - Page 692 of 717
2K+ Views
In this article, we will learn how to convert a binary number to a decimal number and a decimal number to a binary number using C++. This means converting numbers like 5 or 10 into a format that uses only 0s and 1s, and also converting binary numbers back into decimal. Decimal number system has a base of 10 as it uses 10 digits from 0 to 9, while binary has a base of 2 as it uses only 0 and 1. Binary is used in computers because digital devices can only represent two states: on(1) and off(0). Example ... Read More
10K+ Views
In this article, we'll show you how to write a C++ program to find the Greatest Common Divisor(GCD) of two numbers using Recursion. The GCD of two numbers is the largest number that divides both of them without leaving a remainder. It is also known as the Greatest Common Factor (GCF). For example, the GCD of 36 and 60 is 12, because 12 is the largest number that divides both 36 and 60 without a remainder. Using Recursion to Find the GCD To find the GCD, we use recursion. In recursion, a function keeps calling itself with updated ... Read More
2K+ Views
In this article, we'll show you how to write a C++ program to calculate the factorial of a number using recursion . The factorial of a number is the result of multiplying all the positive numbers 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
2K+ Views
In this article, we'll show you how to write a C++ program to create a simple calculator that can add, subtract, multiply, or divide using a switch statement. The calculator works by taking two numbers(operands) and an operator (+, -, *, /) from the user, and then it performs the chosen operation. Lets understand it better with an example: Suppose the user enters: a = 5 and b = 4 Then, based on the chosen operator: If the operator is +, the result is 5 + 4 = 9 If the operator is -, the result is 5 ... Read More
7K+ Views
In this article, we will show you how to check whether a number is prime by creating a function in C++. A prime number is a number greater than 1 that has no divisors other than 1 and itself. For example, 2, 3, 5, 7, and 11 are prime numbers because they have only two divisors (1 and themselves), whereas 4, 6, 8, and 9 are not prime. Using a Function to Check Prime Number To check if a number is prime, we define a function that performs the check and returns true if the number ... Read More
3K+ Views
A palindrome number remains the same if its digits are reversed i.e its value does not change. A palindrome number can also be called symmetric. For example: The numbers 12321, 1551, 11 etc are palindromes as they do not change even if their digits are reversed.A program that checks if a number is palindrome or not is as follows.Example Live Demo#include using namespace std; void palindrome(int num) { int rev=0,val; val = num; while(num > 0) { rev = rev * 10 + num % 10; num = num / 10; } if(val==rev) cout
6K+ Views
In this article, we'll show you how to calculate the power of a number in C++. Calculating a power means multiplying the base by itself as many times as the exponent indicates. For example, 2 raised to the power of 3 (2^3) means multiplying 2 by itself three times: 2 * 2 * 2, which gives 8. In C++, there are different ways to calculate the power of a number. Below are the approaches we cover: Using a Loop Using Recursion Using the pow() Function ... Read More
1K+ Views
In this article, we will show you how to reverse a number using C++. Reversing a number means changing the order of its digits, so the first digit moves to the end, the last digit moves to the front, and the middle digits follow in the opposite order. For example, if we start with the number 1234, the reversed number will be 4321. In C++, we can reverse a number in different ways. Some common approaches we can use are: Using a Loop Using Recursion ... Read More
11K+ Views
In this article, we'll show you how to find the LCM of two numbers in a C++ program. The LCM(Least Common Multiple) is the smallest positive number that is exactly divisible by both numbers. For example, if we take 4 and 5: The multiples of 4 are: 4, 8, 12, 16, 20, 24, ... The multiples of 5 are: 5, 10, 15, 20, 25, ... The first common multiple is 20, so the LCM of 4 and 5 is 20. Approaches to Find LCM in C++ We can find the LCM of two ... Read More
14K+ Views
The Greatest Common Divisor (GCD) of two numbers is the largest number that divides both of them.For example: Let’s say we have two numbers are 45 and 27.45 = 5 * 3 * 3 27 = 3 * 3 * 3So, the GCD of 45 and 27 is 9.A program to find the GCD of two numbers is given as follows.Example Live Demo#include using namespace std; int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } int main() { int a = 105, b = 30; cout