C++ Articles - Page 693 of 719

C++ Program to Calculate Average of Numbers Using Arrays

Nishu Kumari
Updated on 13-May-2025 17:10:42

8K+ Views

An array stores multiple values of the same data type. To find the average, we add all the numbers and then divide the total by how many numbers there are. In this article, we'll show you how to write a C++ program to calculate the average of numbers using an array.  For example, if we have the numbers 40, 80, 10, 75, and 25, their total is 230, and the average is 230 / 5 = 46. Approaches for Calculating Average Using Arrays In C++, we can calculate the average of numbers in an array in two main ... Read More

C++ Program to Calculate Power Using Recursion

Nishu Kumari
Updated on 13-May-2025 17:12:30

5K+ Views

Calculating a power means multiplying the base by itself as many times as the exponent indicates. In this article, we'll show you how to write a C++ program to calculate the power of a number using recursion.  For example, 2 raised to the power of 3 (2^3) means multiplying 2 by itself 3 times: 2 * 2 * 2, which gives 8. Using Recursion to Calculate Power To calculate the power of a number, we use recursion, where a function keeps calling itself with smaller values until it reaches a stopping point. Here are the steps we ... Read More

C++ program to Find Sum of Natural Numbers using Recursion

Nishu Kumari
Updated on 13-May-2025 18:44:02

3K+ Views

Natural numbers are positive numbers starting from 1, such as 1, 2, 3, and so on. Here, we will take a positive number n as input and and then will find the sum of all natural numbers from 1 up to n using recursion using C++ program. Example Input: n = 5 The sum of the first 5 natural numbers is: 1 + 2 + 3 + 4 + 5 = 15 Output: 15 Input: n = 8 The sum of the first 8 natural numbers is: 1 + 2 + 3 + 4 + 5 + 6 ... Read More

C++ Program to Display Prime Numbers Between Two Intervals Using Functions

Nishu Kumari
Updated on 13-May-2025 18:45:09

2K+ Views

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. In this article, we'll show you how to write a C++ program to display prime numbers between two intervals using function. For example, given the interval from 0 to 50, we want to print all the prime numbers within this interval. Input: Starting interval: 0 Ending interval: 50 Output: Prime numbers in the interval [0, 50] are: 2 3 5 7 11 13 17 19 23 29 31 ... Read More

C++ Programs To Create Pyramid and Pattern

Nishu Kumari
Updated on 21-Aug-2025 18:15:52

2K+ Views

In this article, we will show you how to write C++ programs to create different pyramids and patterns. You can create many kinds of patterns using stars, numbers, and alphabets. Below is the list of patterns we will cover in this article- Simple Pyramid Pattern in C++ Flipped Simple Pyramid Pattern in C++ Inverted Pyramid Pattern in C++ Flipped Inverted Pyramid Pattern in C++ Triangle Pattern in C++ Inverted Triangle Pattern in C++ ... Read More

C++ Program to Display Armstrong Number Between Two Intervals

Nishu Kumari
Updated on 15-May-2025 19:43:05

2K+ Views

In this article, we will understand how to display all the prime numbers from 1 to N in Java. All possible positive numbers from 1 to infinity are called natural numbers. A number is a prime number if its only factors are 1 and itself and cannot be divided by any other number. 11 is a prime number. Its factors are 1 and 11 itself. Some examples of prime numbers are 2, 3, 5, 7, 11, 13, and so on. 2 is the only even prime number. All other prime numbers are odd numbers. Below is a demonstration of the ... Read More

C++ Program to Check Armstrong Number

Nishu Kumari
Updated on 15-May-2025 19:43:53

1K+ Views

An armstrong number is a positive integer that is equal to the sum of its digits, each raised to the power of the total number of digits in the number. Our goal here is to check armstrong numbers in C++. In simple terms, for a number with n digits: abcd... = a^n + b^n + c^n + d^n + ... If this condition is satisfied, we can say the number is an armstrong number. Let's understand with examples: 153 is an Armstrong number because: 1^3 + 5^3 + 3^3 = 1 + 125 + 27 = 153 ... Read More

C++ Program to Display Prime Numbers Between Two Intervals

Nishu Kumari
Updated on 13-May-2025 18:46:48

578 Views

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. In this article, we'll show you how to write a C++ program to display prime numbers between two intervals. ExampleFor example, given the interval from 0 to 50, we want to print all the prime numbers within this interval. Input: Starting interval: 0 Ending interval: 50 Output: Prime numbers in the interval [0, 50] are: 2 3 5 7 11 13 17 19 23 29 31 37 41 ... Read More

C++ Program to Find Largest Element of an Array

Nishu Kumari
Updated on 09-May-2025 11:31:59

8K+ Views

In this article, we'll show you how to write a C++ program to find the largest element in an array. An array is a collection of values that share the same data type. Our task is to go through all the elements stored in the array and find the one with the highest value. For example, consider the following arrays: //Example 1 int arr[] = {11, 13, 21, 45, 8}; Here, the largest element is 45. //Example 2 int arr[] = {1, 9, 2, 5, 7}; In this case, the largest element is ... Read More

C++ Program to Convert Binary Number to Decimal and vice-versa

Nishu Kumari
Updated on 09-May-2025 15:31:37

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

Advertisements