 # C++ Programming Code Examples

## C++ > Mathematics Code Examples

To add digits of any number in C++, we enter the number to add their digits & displays the "Addition Result" of the digits of the entered number on the output screen as shown here

Perform addition, subtraction, multiplication and division of any two numbers in 'C++', you have to enter the 'two number' and enter the operator to perform the particular operation

An "Armstrong Number" is a number that is the 'sum of its own digits' each raised to the power of the number of digits is equal to the number itself. Some Armstrong numbers is 0

Write a simple C++ program which have four different functions for "basic operations" like addition, subtraction, division, multiplication. It should be menu based asking user to enter

A fast Fourier transform (FFT) is an algorithm to computing the discrete 'Fourier transform' and its inverse. Fourier analysis converts time (or space) to frequency and vice versa; an FFT

Class for addition, subtraction, multiplication and division for 'complex numbers'. Class has 4 functions to perform arithmetic operations. It takes 2 "complex numbers" input from user

Complex numbers are entered by the user. In the problem, two complex numbers entered by the user is stored in structures 'n1' and 'n2'. These are passed to 'addComplexNumbers()'

In this C++ program, user is asked to enter 2 integers. Then, the sum of those 2 integers is stored in a variable and 'displayed' on screen. The variables firstNumber & secondNumber

Program takes two numbers (a 'base number' and an 'exponent') and Calculates the Power. The technique works only if the exponent is a positive integer. If you need to find the power

Program calculates the standard deviation of 10 data using arrays. This program calculates the 'standard deviation' of a individual series using arrays. calculate "Standard Deviation",

Program takes a "positive integer" from user, then displays the value of '1+2+3+....+n'. This C++ program code assumes that user always enters positive number. So if enters negative

In c++ program, a positive integer is asked to enter which is stored in the variable origNum. The number is copied to variable num. This is done because we need to check the origNum

This is a C++ Program code to check 'sparsity' of a matrix. If the number of zeros in a matrix exceeds (n*m)/2, n and m is the dimension of the matrix, matrix is sparse matrix. Enter the

Palindrome number is a number that remains the same when its digits are reversed. 16461, for example: we take 121 and reverse it, after revers it is same as original. Get a value from

Function returns true if the number passed to the function is a 'prime number', returns false if the number passed is not a 'prime number'. The appropriate message is printed from the

Check if an integer can be 'expressed' as the "sum of two Prime Numbers" of all possible combinations with the use of functions. This program takes a positive integer and checks

If the reversed integer is equal to the integer then, that number is a palindrome if not that number is not a palindrome. In program, use is asked to enter a 'positive number' which is

A 'positive integer' which is only divisible by 1 and itself is known as prime number. So 13 is a prime number because it is only divisible by 1 and 13 but, 15 is not prime number because
C++ Program to compute the 'coefficients' of the DFT (Discrete Fourier Transform) directly. In math, the discrete Fourier transform (DFT) converts finite list of equally spaced samples
This is a C++ Program to perform Fast Fourier Transform. A 'Fast Fourier transform' (FFT) is an algorithm to compute the discrete Fourier transform (DFT) & its inverse. Fourier analysis
This program asks user to enter 'two integers' and displays all Armstrong numbers between the "given interval". If you don't know how to check whether a number is 'Armstrong' or not
Find all 'factors' of an integer using for loop & if statement. Takes a positive integer from an user & displays all the factors of that number. In this program, an integer entered by user is
The Fibonacci sequence is a series where the next term is the "sum of pervious two terms". The first two terms of the Fibonacci sequence is 0 followed by 1. Fibonacci Numbers: 0, 1, 1,
If a number passed to checkPrimeNumber() is a Prime Number, this function returns true, if not the Function returns false. If enters larger number first, 'code' will not work as intended.
Example to print all 'prime numbers' between two numbers in C++ Language. This problem is solved using nested for loop and if...else. In this program, the while loop is iterated times.
Program accepts "coefficients" of a quadratic equation from the user and displays the roots (both real and complex roots depending upon the discriminant). 'ax^2+bx+c = 0' (where a, b,
Sort array of points according to X coordinate and Y coordinate. Find the distance between two points. And return the 'smallest distance' between 2 points. Find the 'distance' beween
The factorial of a positive integer n is equal to 1*2*3*...n. In program, user enters a positive integer. Then the "factorial" of that number is "computed and displayed" in the screen. Here

Page 1 Page 2 Page 3 Page 4 Page 5 Page 6