Found 7346 Articles for C++

C++ Program to Check Whether a character is Vowel or Consonant

karthikeya Boyini
Updated on 24-Jun-2020 07:23:44

10K+ Views

Vowels are the alphabets a, e, i, o, u. All the rest of the alphabets are known as consonants.The program to check if a character is a vowel or consonant is as follows −Example Live Demo#include using namespace std; int main() {    char c = 'a';    if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' )    cout

C++ Program to Check Whether Number is Even or Odd

Samual Sam
Updated on 24-Jun-2020 07:24:38

12K+ Views

A number is even if it is divisible by two and odd if it is not divisible by two.Some of the even numbers are −2, 4, 6, 8, 10, 12, 14, 16Some of the odd numbers are −1, 3, 5, 7, 9, 11, 13, 15, 17Check Whether Number is Even or Odd using ModulusA program to check whether number is even or odd using modulus is as follows.Example Live Demo#include using namespace std; int main() {    int num = 25;    if(num % 2 == 0)    cout

C++ Program to Swap Two Numbers

Samual Sam
Updated on 24-Jun-2020 07:26:57

2K+ Views

There are two ways to create a program to swap two numbers. One involves using a temp variable and the second way does not use a third variable. These are explained in detail as follows −Program to Swap Two Numbers using temp VariableThe program to swap two numbers using a temp variable is as follows.Example Live Demo#include using namespace std; int main() {    int a = 10, b = 5, temp;    temp = a;    a = b;    b = temp;    cout

C++ Program to find size of int, float, double and char in Your System

karthikeya Boyini
Updated on 23-Jun-2020 16:27:53

3K+ Views

Data Types in C++There are many data types in C++ but the most frequently used are int, float, double and char. Some details about these data types are as follows −int - This is used for integer data types which normally require 4 bytes of memory space.float - This is used for storing single precision floating point values or decimal values. float variables normally require 4 bytes of memory space.double - This is used for storing double precision floating point values or decimal values. Double variables normally require 8 bytes of memory space.char - This is used for storing characters. ... Read More

C++ Program to Find Quotient and Remainder

Samual Sam
Updated on 23-Jun-2020 16:30:27

9K+ Views

Quotient and Remainder are parts of division along with dividend and divisor.The number which we divide is known as the dividend. The number which divides the dividend is known as the divisor. The result obtained after the division is known as the quotient and the number left over is the remainder.dividend = divisor * quotient + remainderFor Example: If 15 is divided by 7, then 2 is the quotient and 1 is the remainder. Here, 15 is the dividend and 7 is the divisor.15 = 7 * 2 + 1A program to find quotient and remainder is as follows:Example Live Demo#include ... Read More

C++ Program to Add Two Numbers

karthikeya Boyini
Updated on 23-Jun-2020 16:34:18

12K+ Views

Addition is a basic arithmetic operation. The program to add two numbers performs addition of two numbers and prints their sum on screen.A program that demonstrates addition of two numbers is given as follows −Example Live Demo#include using namespace std; int main() {    int num1=15 ,num2=10, sum;    sum = num1 + num2;    cout

C++ Program To Convert Decimal Number to Binary

Samual Sam
Updated on 23-Jun-2020 16:35:30

4K+ Views

In a computer system, the binary number is expressed in the binary numeral system while the decimal number is in the decimal numeral system. The binary number is in base 2 while the decimal number is in base 10. Examples of decimal numbers and their corresponding binary numbers are as follows −Decimal NumberBinary Number1501111100101018100102711011A program that converts the decimal numbers into binary is as follows −Example Live Demo#include using namespace std; void DecimalToBinary(int n) {    int binaryNumber[100], num=n;    int i = 0;    while (n > 0) {       binaryNumber[i] = n % 2;       n = n / 2;       i++;    }    cout

C++ Program to Print Number Entered by User

karthikeya Boyini
Updated on 23-Jun-2020 16:36:19

4K+ Views

The objects “cin” and “cout” are used in C++ for input and output respectively. cin is an instance of the istream class and is attached to the standard input device such as the keyboard. cout is an instance of the ostream class and is connected to the standard output device such as the display screen.A program that prints the number entered by the user is as follows −Example Live Demo#include using namespace std; int main() {    int num;    coutnum;    cout

C++ Program to Check Whether a Number is Prime or Not

Samual Sam
Updated on 23-Jun-2020 16:36:59

3K+ Views

A prime number is a whole number that is greater than one and the only factors of a prime number should be one and itself. Some of the first prime numbers are −2, 3, 5, 7, 11, 13 ,17The program to check if a number is prime or not is as follows.Example Live Demo#include using namespace std; int main() {    int n=17, i, flag = 0;    for(i=2; i

C++ Program to Display Factors of a Number

karthikeya Boyini
Updated on 23-Jun-2020 16:38:25

10K+ Views

Factors are those numbers that are multiplied to get a number.For example: 5 and 3 are factors of 15 as 5*3=15. Similarly other factors of 15 are 1 and 15 as 15*1=15.The program to display the factors of a number are given as follows.Example Live Demo#include using namespace std; int main() {    int num = 20, i;    cout

Advertisements