CPP program to reverse a number

The below program can be used to reverse a given number using a loop. The CPP cout object is used to output the result on the screen. Reverse Number of abcde = edcba. Code: #include <iostream.h> using namespace std;   int main() { int num, x = 0; int mod;   cout << "Enter a … Read more

Categories CPP

CPP program to print sum of digits

The below program gives the sum of all the digits in a variable using loop. The CPP cout object is used to output the result on the screen. Logic: Till the given Number is greater than 0. Remainder = Modulus of Number with 10 Total Sum = Adding Remainder into the Total Sum Number = … Read more

Categories CPP

CPP program to check for an Armstrong number

The below program checks for an Armstrong number using a loop. The CPP cout object is used to output the result on the screen. A number is called as an Armstrong number if the sum of the cubes of its digits is equal to the number itself. Armstrong Number: abc = (a*a*a) + (b*b*b) + … Read more

Categories CPP

CPP program to print factorial of a number

The below program prints factorial of a number using a loop and using recursion. The CPP cout object is used to output the result on the screen. The factorial of a number can be calculated for positive integers only and is represented by n!. n! = n*(n-1)*(n-2)*……*1 0! = 1 Code: Using Loop #include <iostream.h> … Read more

Categories CPP

CPP program to check for a Palindrome number

The below program checks for a Palindrome number using a loop. The CPP cout object is used to output the result on the screen. A number is called as a Palindrome number if the number remains same even when its digits are reversed. Palindrome Number: abcde = edcba Example: 24142, 1234321, etc. Code: #include <iostream.h> … Read more

Categories CPP

CPP program to check prime number

The below program checks if a number is a prime or a composite number. The CPP cout object is used to output the result on the screen. Code: #include <iostream.h> using namespace std;   int main() { int x,i; int count = 0;   cout << "Enter a number:"; cin >> x;   for (i=1; … Read more

Categories CPP

CPP program to print fibonacci series

The below program prints a Fibonacci Series without recursion. The CPP cout object is used to output the result on the screen. A series is called as a Fibonacci series if the each next term of the series is a sum of previous two numbers. Fibonacci Series: a, b, c, d, e   c = … Read more

Categories CPP

CPP Destructor

Unlike CPP Constructors, a CPP destructor is defined only once in a class in order to destroy the objects of that class. It has the same name as the name of the class, prefixed with a tilde sign (~). Example: #include <iostream.h> using namespace std;   class Employees { public: string Name; float Salary; Employees() … Read more

Categories CPP

CPP Constructors

CPP facilitates a special type of method, also called as CPP Constructors, to initialize the instance members of the class and to verify enough object resources for executing any startup task. It has the same name as the name of the class.   Types of Constructors:  Default Constructor: A Default Constructor is automatically created at … Read more

Categories CPP

CPP Object Class

CPP introduced the features of OOPs Concept, i.e, CPP is an object-oriented programming language which uses classes and objects for computations. CPP Class: A collection of Objects is termed as Class in OOPs concept. Every class has its own unique and distinguishable attributes and methods. Syntax: class ClassName: <statement-1>      .      .      .  … Read more

Categories CPP