Found 33676 Articles for Programming

C++ Program to Make a Simple Calculator to Add, Subtract, Multiply or Divide Using switch...case

Nishu Kumari
Updated on 09-May-2025 15:50:08

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

C++ Program to Check Prime Number By Creating a Function

Nishu Kumari
Updated on 09-May-2025 16:05:32

6K+ 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

C++ Program to Check Whether a Number is Palindrome or Not

karthikeya Boyini
Updated on 24-Jun-2020 07:57:21

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

C++ Program to Calculate Power of a Number

Nishu Kumari
Updated on 09-May-2025 15:17:36

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

C++ Program to Reverse a Number

Nishu Kumari
Updated on 09-May-2025 15:18:28

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

C++ Program to Find LCM

Nishu Kumari
Updated on 09-May-2025 15:28:41

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

C++ Program to Find GCD

Samual Sam
Updated on 24-Jun-2020 07:31:44

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

C++ Program to Generate Multiplication Table

Nishu Kumari
Updated on 13-May-2025 17:06:55

5K+ Views

In this article, we will show you how to write a C++ program to generate the multiplication table of a number. A multiplication table shows how a number is multiplied by 1 to 10 and helps define the multiplication operation for that number. Each row displays the result of multiplying the number by values from 1 to 10. For example, the multiplication table of 4 looks like this: 4 * 1 = 4 4 * 2 = 8 4 * 3 = 12 4 * 4 = 16 4 * 5 ... Read More

C++ Program to Find Factorial

Nishu Kumari
Updated on 09-May-2025 15:30:29

23K+ Views

In this article, we'll show you how to write a C++ program to find the factorial of a number. 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 * 3 * 2 ... Read More

C++ Program to Check Leap Year

Nishu Kumari
Updated on 13-May-2025 17:07:56

14K+ Views

A leap year contains one additional day, i.e february 29, to keep the calendar year synchronized with the earth's orbit around the sun. We will write a C++ program that checks whether a given year is a leap year or not. A year that is divisible by 4 is known as a leap year. However, years divisible by 100 are not leap years while those divisible by 400 are. Here is a list of some leap years and non-leap years: ... Read More

Advertisements