 # C++ Programming Code Examples

## C++ > Mathematics Code Examples

### C++ Program to Calculate Power of a Number

``` C++ Program to Calculate Power of a Number In this article, you will learn to compute power to a number manually, and by using pow() function. This program takes two numbers from the user (a base number and an exponent) and calculates the power. Power of a number = base^exponent The above technique works only if the exponent is a positive integer. If you need to find the power of a number with any real number as an exponent, you can use pow() function. #include <iostream> using namespace std; int main() { int exponent; float base, result = 1; cout << "Enter base and exponent respectively: "; cin >> base >> exponent; cout << base << "^" << exponent << " = "; while (exponent != 0) { result *= base; --exponent; } cout << result; return 0; } ```

C Calculate the Sum of the Array Elements - C Program code calculates the sum of array elements using pointer. The program uses the pointer to traverse the array and adds up the element values there. C program to read

C++ Implement Stack using Two Queues - This C++ program implements a "stack data" structure using two queue data structures. A stack data structure foolows the principle of LIFO(last element in first element out). Enter

Create an inline Function in C++ language - When one 'function calls another', the calling function must "Send a Request" to the called function that would process it and return the necessary value, if any. C++ Language allows

C Code interchange Diagonals of a Matrix - C programming code to read elements in a matrix and interchange elements of primary (major) diagonal with secondary (minor) diagonal. C program code for interchanging

C Program Computes Factorial of number - The Factorial of a Positive Number n is given by: factorial of n (n!) = 1*2*3*4...n. Factorial of a negative number doesn't exist. And, the factorial of 0 is 1, 0! = 1. The program takes a

Program Convert Hexadecimal to Decimal - To convert a number from "hexadecimal" into equivalent decimal format "in C++", enter the hexadecimal number to convert it to decimal to display the equivalent value in "decimal" as

Write inline assembly language code in C - Adding two numbers using inline assembly language. Assembly language can be written in c. C supports assembly as well as higher language features so called "middle level...

C Code Check Palindrome Using Recursion - In this article we have shared two C programs to check if the input number is palindrome or not. 1) using while loop 2) using recursion. If a number 'remains same', even if we reverse its