- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 7346 Articles for C++
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
5K+ Views
The power of a number can be calculated as x^y where x is the number and y is its power.For example.Let’s say, x = 2 and y = 10 x^y =1024 Here, x^y is 2^10 Power of a number can be calculated using recursive and non-recursive programs. Each of these are given as follows.Power of a Number Using Non-Recursive ProgramThe program to find the power of a number using a non-recursive program is given as follows −Example Live Demo#include using namespace std; int power(int x, int y) { int i,power=1; if(y == 0) return 1; for(i=1;i
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
977 Views
Reversing a number means storing its digits in reverse order.For example: If the number is 6529, then 9256 is displayed in the output.A program to reverse a number is given as follows −Example Live Demo#include using namespace std; int main() { int num = 63972, rev = 0; while(num > 0) { rev = rev*10 + num%10; num = num/10; } cout
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
10K+ Views
The Least Common Multiple (LCM) of two numbers is the smallest number that is a multiple of both.For example: Let’s say we have the following two numbers: 15 and 9.15 = 5 * 3 9 = 3 * 3So, the LCM of 15 and 9 is 45.A program to find the LCM of two numbers is given as follows −Example Live Demo#include using namespace std; int main() { int a=7, b=5, lcm; if(a>b) lcm = a; else lcm = b; while(1) { if( lcm%a==0 && lcm%b==0 ) { cout
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
13K+ 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
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
4K+ Views
The multiplication table is used to define a multiplication operation for any number. It is normally used to lay the foundation of elementary arithmetic operations with base ten numbers.The multiplication table of any number is written till 10. In each row, the product of the number with 1 to 10 is displayed. An example of the multiplication table of 4 is as follows −4 * 1 = 4 4 * 2 = 8 4 * 3 = 12 4 * 4 = 16 4 * 5 = 20 4 * 6 = 24 4 * 7 = 28 4 * 8 = 32 4 * 9 = 36 4 * 10 = 40A program that generates the multiplication table of the given number is as follows.Example Live Demo#include using namespace std; int main() { int n = 7, i; cout
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
21K+ Views
Factorial of a non-negative integer n is the product of all the positive integers that are less than or equal to n.For example: The factorial of 5 is 120.5! = 5 * 4 * 3 * 2 *1 5! = 120The factorial of an integer can be found using a recursive program or a non-recursive program. Example of both of these are given as follows.Factorial using Non-Recursive ProgramA for loop can be used to find the factorial of a number. This is demonstrated using the following program −Example Live Demo#include using namespace std; int main() { int n = 5, fact = 1, i; for(i=1; i
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
12K+ Views
A leap year contains one additional day that is added to keep the calendar year synchronized with the astronomical year.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.The program that checks if a year is leap year or not is as follows −Example Live Demo#include using namespace std; int main() { int year = 2016; if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) cout
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
2K+ Views
The natural numbers are the positive integers starting from 1.The sequence of natural numbers is −1, 2, 3, 4, 5, 6, 7, 8, 9, 10……Sum of the first n natural numbers can be calculated using the for loop or the formula.Programs specifying both of these methods are given as follows −Sum of Natural Numbers Using for loop.The program to calculate the sum of n natural numbers using for loop is given as follows.Example Live Demo#include using namespace std; int main() { int n=5, sum=0, i; for(i=1;i
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
7K+ Views
A quadratic equation is in the form ax2 + bx + c. The roots of the quadratic equation are given by the following formula −There are three cases −b2 < 4*a*c - The roots are not real i.e. they are complexb2 = 4*a*c - The roots are real and both roots are the same.b2 > 4*a*c - The roots are real and both roots are differentThe program to find the roots of a quadratic equation is given as follows.Example#include #include using namespace std; int main() { int a = 1, b = 2, c = 1; float discriminant, ... Read More