100 C++ basic programming exercises and solutions

C++ basic programming exercises and solutions for beginners. This C++ page has the basic to advanced programs to understand concepts like functions, class and etc.

C++ program is print the smallest missing element in sorted array

C++ program is printing the smallest missing element in a sorted array. Using this program to the smallest missing element in the array. An array is a collection of elements of the same kind that are stored in contiguous memory locations and may be accessed separately using a unique identifier’s index. Without having to define five individual variables, an array of five int values can be declared.

#include<iostream>
#include<algorithm>
using namespace std;
int small(int arr[], int start, int end)
{
if (start > end)
return end + 1;
if (start != arr[start])
return start;
int mid = (start + end) / 2;
if (arr[mid] == mid)
return small(arr, mid + 1, end);
return small(arr, start, mid);
}
int main()
{
int arr[100], n, i;
cout << "Enter number of elements";
cin >> n;
cout << "\nEnter elements";
for (i = 0; i < n; i++)
cin >> arr[i];
cout << "Original array";
for (int i = 0; i < n; i++)
cout << arr[i] << " ";
int answer;
answer = small(arr, 0, n - 1);
cout << "\nSmallest missing element is " << answer;
return 0;

}

Enter number of elements3

Enter elements45
67
89
Original array45 67 89
Smallest missing element is 0

What is array and how to implement in c++ program

The array is a data structure in C++ that stores a fixed-size sequential collection of objects of the same type in a fixed-size sequential order. Although an array is used to hold data, it is often more beneficial to conceive of it as a collection of variables of the same type. All arrays are made up of memory regions that are connected in some way.

What is return statement in c++ program

A return statement marks the end of a function’s execution and hands control back to the calling function. The calling function continues execution at the place where the call was made. A return statement can give the caller function a value.

C++ program to print the cube root of a number

C++ program to print the cube root of a number. Using this program to print we can execute the C++ program with cube root function. The cube root of a number an is the number that, when multiplied three times, yields the number ‘a’. As a result, 3125 = 5 is the cube root of 125.

#include <iostream>
#include <cmath>
using namespace std;
int main()
{
float num, ans;
cout << "Enter the num";
cin >> num;
ans = cbrt(num);
cout << "\n Cube root of " << num << " is: " << ans;
}

Output:

Enter the num 5

Cube root of 5 is: 1.70998

What is cmath function in c++ program

The cmath> header file in C++ provides a set of functions for performing mathematical operations, such as sqrt() for calculating the square root, log() for finding the natural logarithm of a number, and so on.

What is cbrt() function in c++ program

std::cbrt() is a built-in function in the C++ STL that calculates the cube root of an integer. It takes an integer as an argument and returns the number’s cube root. A number’s cube root is a value that, when multiplied by itself three times, returns the original value. For example, the cube root of 27, written as 327, is 3, because we get 3 x 3 x 3 = 27 = 33 when we multiply 3 by itself three times.

C++ program to print the square root

C++ program to print the square root. The cmath> header file in C++ provides a set of functions for performing mathematical operations, such as sqrt() for calculating the square root, log() for finding the natural logarithm of a number, and so on.

#include<iostream>
#include<math.h>
using namespace std;
int main()
{
float num, root;
cout << "Enter the num for sqrt";
cin >> num;
root = sqrt(num);
cout << "Square root of " << num << " is " << root;
return 0;
}

Output:

Enter the num for sqrt1500
Square root of 1500 is 38.7298

What is math.h and how to implement in c++ program

You must include the header files math. h> and cmath> in order to utilise these functions. sin(double) double sin(double) sin(double) sin(double) sin(double) This function accepts an angle (in degrees) and returns its sine value, which can be confirmed using a sine curve. h is a header file in the C programming language’s standard library that is used to perform fundamental mathematical calculations. Integer-operating mathematical library functions, such as abs, labs, div, and ldiv, are instead supplied in the stdlib.

What is SQRT function program in c++

One of the math and trigonometry functions is the SQRT function. It’s used to calculate a number’s square root. where x is a numeric value explicitly inputted or contained in the cell you’re referring to.

C++ program to print the minimum and maximum element of the array

C++ program to print the minimum and maximum element of the array. Using this program we can easily find the size of the array’s min and max elements. A data structure that contains a group of elements is known as an array. These items are often all of the same data type, such as an integer or a string. In computer programs, arrays are widely used to organize data so that a related group of numbers can be readily sorted or searched.

#include <iostream>
using namespace std;
int main()
{
int array[500], *max, *min, size, i;
cout<<"Enter the size of an array\n";
cin>>size;
cout<<"Enter array elements\n";
for ( i = 0 ; i < size ; i++ )
cin>>array[i];
max = array;
min = array;
for (i = 0; i < size; i++)
{
if (*(array+i) > *max)
*max = *(array+i);
}
cout<<"Maximum element in the array is "<< *max << "\n" ;
for (i = 0; i < size; i++)
{
if (*(array+i) < *min)
*min = *(array+i);
}
cout<<"Minimum element in the array is"<< *min <<"\n";
return 0;
}

Output:

Enter the size of an array
5
Enter array elements
45
67
78
45
34
Maximum element in the array is 78
Minimum element in the array is34

DIfference between min and max function in c++ program

The min() function is an algorithm header library function that is used to determine the smallest value from two values. It accepts two values and returns the smallest value, or the first value if both values are the same.

max Algorithm in C++ () In C++, the max() function can be used in three ways: It compares the two parameterized values and returns the greater of the two. If they’re both equal, the first is returned.

What is array in c++ programming

An array is a data structure that can hold a fixed number of elements of the same data type in a fixed size. Although an array is used to hold data, it is often more beneficial to conceive of it as a collection of variables of the same type.

C++ program to print the addition of two numbers using pointers

C++ program to print the addition of two numbers using pointers. Using this program you can print the addition of two numbers. Addresses are represented by pointers, which are symbolic representations of them.

They allow programs to generate and modify dynamic data structures as well as imitate call-by-reference. Its standard C/C++ declaration looks like this: Syntax: datatype *var name; int *ptr; /ptr can point to an address that contains int data.

#include <iostream>
using namespace std;
int main()
{
int a, b;
int *ptr1,* ptr2;
int sum;
cout<<"\n Enter first number";
cin>>a;
cout<<"\n Enter second number";
cin>>b;
ptr1 = &a;
ptr2 = &b;
sum = *ptr1 + * ptr2;
cout<<"\n Sum is: "<< sum;
return 0;
}

Output:

Enter first number 34

Enter second number 45

Sum is: 79

What is pointer in c++ program

A variable that stores the address of another variable is known as a pointer. A pointer is a variable that holds the address of a variable, unlike other variables that hold values of a specific type. An integer variable, for example, stores (or holds) an integer value, whereas an integer pointer holds the address of an integer variable.

What is cin in c++ program

In C++, the cin object belongs to the istream class. It accepts input from a normal input device, such as a keyboard. It’s linked to stdin, the standard C input stream. For reading inputs, the extraction operator(>>) is combined with the object cin.

Pascal triangle pattern program in c++ using for loop

A Pascal triangle pattern program in c++. Using this program we can print the pascal pattern program using for loop. Pascal’s Triangle is a numerical pattern with a triangle shape. It is named after the French mathematician Blaise Pascal. Pascal’s Triangle is used in mathematics and statistics for a variety of purposes, including assisting in the calculation of combinations.

#include <iostream>
using namespace std;
int main()
{
int n, k = 0;
cout<<"Enter the number of rows";
cin>> n;
cout<<"\n";
for (int i = 1; i <= n; ++i)
{
for (int j = 1; j <= n - i; ++j)
cout<<" ";
k=0;
while (k != 2 * i - 1)
{
cout<<"* ";
++k;
}
cout<<"\n";
}
return 0;
}

Output:

Enter the number of rows 3

      *
   * * *
* * * * *

How to execute the pascal triangle pattern program in c++

We’ll use three loops to print the Pascal’s triangle: two for loops and one while loop. The number of rows is printed using the first loop. The spaces between the stars are printed using the second loop. The stars are printed using the third loop, the while loop.

What is for loop in c++ program

A for loop is a repetition control structure that lets you design a loop that needs to run a certain number of times quickly.

What is while loop in c++ program

A while loop is a control flow statement that runs a block of code at least once before deciding whether or not to run it again based on a boolean condition at the conclusion of the block.

C++ program to swap or transpose a matrix by using multi-dimensional arrays

C++ program to swap or transpose a matrix by using multi-dimensional arrays. Using this program to print the transpose of the matrix. A matrix is a rectangular array of numbers that are arranged in rows and columns. The numbers are referred to as the matrix’s elements or entries. Engineering, physics, economics, and statistics, as well as various disciplines of mathematics, all use matrices.

#include<iostream>
using namespace std;
int row,col;
int main()
{
int val,row,col;
cin>>row;
cin>>col;
int a[row][col];
cout<<"\n a: \n";
for(int i=0;i<row;i++)
{
for(int j=0;j<col;j++)
{
cin>>val;
a[i][j]=val;
}
}
int b[col][row];
for(int j=0;j<row;j++)
{
for(int i=0;i<col;i++)
b[i][j]=a[j][i];
}
for(int i=0;i<col;i++)
{
for(int j=0;j<row;j++)
a[i][j]=b[i][j];
}
for(int i=0;i<col;i++)
{
for(int j=0;j<row;j++)
cout<<a[i][j]<<" ";
cout<<"\n";
}
return 0;
}

Output:

2
2

a:
34
45
56
67


34 56
45 67

What is matrix and how to implement in c++ program

A matrix is a set of numbers organized into a predetermined number of rows and columns. The numbers are usually real numbers. Complex numbers can be found in matrices in general, but we won’t encounter them here. An example of a three-row, three-column matrix is as follows: Row 1 is at the top of the list.

What is transpose matrix and how to implement in c++ program

“A Matrix that is generated by changing all the rows of a given matrix into columns and vice versa,” according to the definition. Given a matrice of order 43, find the solution. The transpose of a matrix is achieved by swapping rows and columns. A matrix is “flipped” over its diagonal. The rows and columns are switched around. The value in the first row and third column, for example, ends up in the third row and first column.

What is namespace in c++ program

A namespace is a C++ feature that is not available in C. A namespace is a declarative zone that gives the identifiers (names of types, functions, variables, and so on) within it a scope. It is permissible to have many namespace blocks with the same name. The named scope is used for all declarations within those blocks.

C++ program to calculate Body Mass Index (BMI) with pounds and inches

A simple C++ program to calculate Body Mass Index (BMI) with pounds and inches. The BMI is calculated by dividing a person’s weight in kilogrammes by the square of their height in metres.

A high BMI indicates a high level of body fatness. BMI detects weight categories that may cause health concerns, however it does not diagnose an individual’s body fatness or health.

#include<iostream>
using namespace std;
int main()
{
float bmi,w,h;
cout<<"enter weight in pounds";
cin>>w;
cout<<"enter height in inches";
cin>>h;
bmi=(w*703)/(h*h);
cout<<"Your BMI is : "<<bmi<<endl;
if(bmi>25)
cout<<"Overweight";
else if(bmi<25 && bmi>18.5)
cout<<"Optimal";
else
cout<<"Underweight";
return 0;
}

Output:

enter weight in pounds45
enter height in inches170
Your BMI is : 1.09464
Underweight

How to calculate the bmi of person in c++ program using formula

What is the formula for calculating BMI? The BMI is a straightforward calculation based on a person’s height and weight. BMI = kg/m2, where kg represents a person’s weight in kilogrammes and m2 represents their height in metres squared. Overweight is defined as a BMI of 25.0 or higher, while the healthy range is 18.5 to 24.9.

Why BMI is important

BMI is a measurement of body fat and a reliable indicator of your risk of diseases associated with excess body fat. Heart disease, high blood pressure, type 2 diabetes, gallstones, respiratory issues, and some malignancies are all linked to a high BMI.

What is float value in c++

A number followed by a decimal point is assumed to be a floating-point constant in C++. As a result, it is assumed that 2.5 is a floating point number. Even if the number to the right of the decimal point is zero, this decimal-point rule holds. As a result, 3.0 is also a floating point number.

A floating-point or float variable is a type of variable in programming that is used to hold floating-point number values. A floating-point number is one in which the decimal point can “float” within the number rather than being in a fixed position.

C++ Program to print the sum of diagonal elements of a matrix

C++ Program to print the sum of diagonal elements of a matrix. We’ll learn how to construct a C++ program to find the sum of a matrix’s diagonal elements in this programming example.

A square matrix has two diagonals, one on the left and one on the right. The row and column indexes of the left diagonal elements are equal, i==j, and the sum of the indices of the right diagonal elements is one less than the size of the matrix, i+j == size-1.

#include <iostream>
#define SIZE 10
using namespace std;
int main()
{
int matrix[SIZE][SIZE];
int left =0, right = 0;
cout << "Enter the elements in the matrix\n";
for(int i=0; i<SIZE ; i++){
for(int j=0; j<SIZE; j++){
cin >> matrix[i][j];
if(i==j)
left += matrix[i][j];
if((i+j) == SIZE-1)
right += matrix[i][j];
}
}
cout << "Sum of the left diagonal elements"<< left << endl;
cout << "Sum of the right diagonal elements "<< right << endl;
return 0;
}

4

1 2 3 4 4 3 2 1 7 8 9 6 6 5 4 3

Output:

Sum of the left Diagonal elements: 16

Sum of the right Diagonal elements: 20

What is diagonal matrix and its value

The main diagonal, also known as the leading diagonal, runs from the top left corner to the bottom right corner of a square matrix. Antidiagonal or counter diagonal is the other diagonal that runs from the top right to the bottom left corner. 

Lower triangular, upper triangular, and diagonal are all properties of a zero square matrix. Assuming it’s a square matrix. All items below the main diagonal in an upper triangular matrix are zero.

Namespace in C++ and why it is bad in program

A namespace is a declarative region that gives the identifiers within it a scope. Namespaces are used to arrange code into logical categories and to avoid name clashes, which might happen when you have many libraries in your codebase.

To contain this change, they built the std namespace. While this is acceptable for example code, importing the full std namespace into the global namespace is not recommended because it contradicts the purpose of namespaces and can result in name clashes.

What is #define in c and c++

The #define directive in the C programming language allows you to define macros within your source code. These macro definitions allow you to declare constant values that you can use throughout your code. Macro definitions aren’t variables, thus they can’t be altered by your computer code.

In the programming languages C and C++, sizeof is a unary operator. It calculates the number of char-sized units required to store an expression or a data type. The preprocessor macro CHAR BIT, defined in the standard include file limits, specifies the actual number of bits of type char. h.

C++ program to calculate students mark and grade

C++ program to calculate students marks and grades. Find a student’s grade based on their performance in five subjects. Using a user-defined function, determine a student‘s grade based on marks earned in all subjects. The user can enter an unlimited number of subjects here.

A floating-point value is expressed as a mantissa plus an exponent or as a whole plus fractional digits (like decimal values). Float8 and double precision are synonyms for float. Four or eight bytes are used to store floating-point integers. Eight-byte integers are internally rounded to fifteen decimal digits.

#include<iostream>
using namespace std;
int main()
{
int marks[5], i;
float sum=0,avg;
cout<<"\n Enter the students marks\n";
cout<<"\n Geography";
cin>>marks[0];
cout<<"\n English";
cin>>marks[1];
cout<<"\n Maths";
cin>>marks[2];
cout<<"\n History";
cin>>marks[3];
cout<<"\n Science";
cin>>marks[4];

for(i=0;i<5;i++)
{
sum=sum+marks[i];
}
cout<<"\n Total marks of student"<<sum;
avg=sum/5;
cout<<"\n Average = "<<avg;
cout<<"\n Grade = ";
if(avg>80)
{
cout<<"A";
}
else if(avg>60 && avg<=80)
{
cout<<"B";
}
else if(avg>40 && avg<=60)
{
cout<<"C";
}
else
{
cout<<"D";
}
return 0;
}

Output:

Enter the student’s marks

Geography99

English88

Maths66

History67

Science56

Total marks of student376
Average = 75.2
Grade = B

What is purpose of namespace in c++

You may specify the context in which names are defined by using namespace. A namespace, in essence, establishes a scope. C++ includes a standard library that contains common features like containers and algorithms that you’ll utilise in your programmes.

c++ program to count the total number of characters in a given text

Write a c++ program to count the total number of characters in a given text. By using this program we can find the number of letters in the letter or character entered by the user in output. It will help for the note writers and some other educanist.

#include <iostream>
using namespace std;
int main()
{
char str[100];
int i,value;
value=0;
cout<<"Enter the letter or characters\n";
cin>> str;
for(i=0; str[i] != '\0'; i++)
{
if(str[i]!=' ')
{
value++;
}
}
cout<<"The total characters are present in the program "<<value;
return 0;
}

Enter the letter or characters
inlarn.com
The total characters are present in the program 10

What is post increment in c++ program

Post-increment operator: A post-increment operator is used to increase the value of a variable after the expression has been fully executed. Value is first utilized in an expression and then increased in the Post-Increment.

For loop and how to implement for loop

A loop is used to continually execute a set of statements until a certain condition is met. When showing numbers from 1 to 100, for example, you might wish to set the value of a variable to 1 and display it 100 times, raising its value by 1 with each loop iteration.

Write a c++ program to print the selection sort

Write a c++ program to print the selection sort. This is also a sorting algorithm to arrange the element in the program in C++. Selection sorting means value is selected for every time to sort the values before sorting in selection sorting in c++ programming language.

#include <iostream>
using namespace std;
void swap(int *a, int *b) 
{
int temp = *a;
*a = *b;
*b = temp;
}
void array(int array[], int size)
{
for (int i = 0; i < size; i++) 
{
cout << array[i] << " ";
}
cout << endl;
}
void sort(int array[], int size) 
{
for (int step = 0; step < size - 1; step++)
{
int min_idx = step;
for (int i = step + 1; i < size; i++) 
{
if (array[i] < array[min_idx])
min_idx = i;
}
swap(&array[min_idx], &array[step]);
}
}
int main() 
{
int data[] = {45,576,34,57,23};
int size = sizeof(data) / sizeof(data[0]);
sort(data, size);
cout << "After sorting\n";
array(data, size);
}

Output:

After sorting 23 34 45 57 576

What is sorting and why selection sort is used

Sorting is the process of arranging data in a chosen order in a data structure. Sorting data makes it simpler to swiftly and simply search through it. A dictionary is the most basic example of sorting. The selection sort algorithm sorts an array by continually choosing the smallest member from the unsorted section and placing it at the beginning (in ascending order). In a given array, the algorithm keeps two subarrays.

Write a c++ program to print Armstrong number for three digits

Write a c++ program to print Armstrong number for three digits. This program will help you to find the Armstrong number in C++. These are basic set program in every programming lanuguage for beginners.

#include <iostream>
using namespace std;
int main() 
{
int num, num1, rem, result = 0;
cout << "Enter the number";
cin >> num;
num1 = num;
while (num1 != 0)
{
rem = num1 % 10;
result += rem * rem * rem;
num1 /= 10;
}
if (result == num)
cout << num << " is Armstrong number";
else
cout << num << " is not Armstrong number";
return 0;
}

Output:

Enter the number567

567 is not Armstrong number

What is armstrong and why it is called armstrong number in c++ program

A number equal to the sum of its digits’ cubes is known as an Armstrong number. An Armstrong three-digit number is an integer in which the total of its digits’ cubes equals the number itself. 371 is an Armstrong number, for example, since 3**3 + 7**3 + 1**3 Equals 371.

Write a program to print factorial of n number in c++

Write a program to print factorial of n numbers in c++. Here’s the sample program for factorial number in c++ for beginners in programming language. This program will help you to find the factorial in C++ programming language.

#include <iostream>
using namespace std;
int main()
{
int n;
long long fact = 1;
cout << "Enter a positive integer: ";
cin >> n;
for(int i = 1; i <=n; ++i)
{
fact *= i;
}
cout << "fact of " << n << " = " << fact; 
return 0;
}

Output:

Enter a positive integer: 5

fact of 5 = 120

What is factorial in java programming

The product of all positive integers less than or equal to a particular positive integer, represented by that integer and an exclamation point in mathematics. As a result, factorial seven is expressed as 7!, which means 1 2 3 4 5 6 7. The factorial zero is equal to one.

Write a c++ program to check whether the given string is palindrome or not

Write a c++ program to check whether the given string is palindrome or not. This program will check the number is palindrome or not which is the number same after reversed in the c++ programming language. This program helps you to find the palindrome in the C++ language. Character-unit palindromes are the most well-known palindromes in English. Backward and forwards, the characters are the same. Redivider, deified, civic, radar, level, rotor, kayak, reviver, racecar, madam, and refer are some instances of palindromic terms.

#include <iostream>
using namespace std;
int main()
{
int n, num, count, rev = 0;
cout << "Enter the number";
cin >> num;
n = num;
do
{
count = num % 10;
rev = (rev * 10) + count;
num = num / 10;
} 
while (num != 0);
cout << "The reverse number is" << rev << endl;
if (n == rev)
cout << " The number is palindrome";
else
cout << " The number is not palindrome";
return 0;
}

Output:

Enter the number 4554                                                                                                                 

The reverse number is 4554                                                                                                           

 The number is palindrome 

What is while loop and why its required

The while loop is a programming construct that repeats a portion of code an undetermined number of times until a condition is fulfilled. Let’s assume we want to know how many times we can divide a certain integer by 2 before it becomes less than or equal to 1.

What is if else condition and why its required

The if block will be performed if the Boolean statement evaluates to true; else, the else block will be executed. Any non-zero and non-null values are presumed to be true in the C programming language, whereas zero and null values are believed to be false.

C++ program to find the sum of n numbers using for loop

C++ program to find the sum of n numbers using for loop. Check the year is leap or not program in C++. This program will check the year whether it is leap year or not. This program will print the set of multiple number to add in a single program in c++ programming language

#include <iostream>
using namespace std;
int main()
{
int i,n, sum = 0;
cout << "Enter the number";
cin >> n;
for (i = 1; i <= n; ++i)
{
sum += i;
}
cout << "Sum = " << sum;
return 0;
}

Output:

Enter the number

44

Sum = 990

What is for loop and how it works

A loop is used to continually execute a set of statements until a certain condition is met. When showing numbers from 1 to 100, for example, you might wish to set the value of a variable to 1 and display it 100 times, raising its value by 1 with each loop iteration.

C++ program to find leap year using nested if

C++ program to find leap year using nested if. Check the year is leap or not program in C++. This program will check the year whether it is leap year or not. Here’s the easiest way to find the year is leap year or not in simple c++ program for beginners in c++ programming language.

#include <iostream>
using namespace std;
int main() 
{
int year;
cout << "Enter the number";
cin >> year;
if (year % 4 == 0)
{
if (year % 100 == 0)
{
if (year % 400 == 0)
cout << year << " is leap year";
else
cout << year << " is not leap year";
}
else
cout << year << " is leap year";
}
else
cout << year << " is not leap year";
return 0;
}

Output:

Enter the number

2020

2020 is leap year

What is leap year and why it happens for every four years

The Earth’s orbit around the Sun takes around 365.25 days – a solar year. The days of a calendar year are generally rounded to 365. Every four years, we add one day to our calendar to compensate for the lost partial day. There are 366 days in a year, thus there are 366 days in a year. This is referred to as a leap year.

“And because February was the final day of the year, an extra date was added in February to ensure that the first day of spring always coincided with the correct time.” A leap year occurs every four years on average, but there are outliers. If a year is equally divisible by four, it is a leap year.

What is nested if else in c++ programming

An if-else statement containing another if statement as the if body or the else body is known as a nested if statement. Here’s an illustration:  Evaluate the outer if condition if the outer if condition evaluates to true. Run the if body if it evaluates to true.

C++ program to check vowel or consonant using if else

C++ program to check vowel or consonant using if else. Check the word is vowel or Consonant in C++ programs. This program will check the word whether it is vowel or consonant in C++. Checking the word is vowel or consonant in c++ program and print the whether the letter is vowel or not 

#include <iostream>
using namespace std;
int main()
{
char c;
bool lowercase, Uppercase;
cout << "Enter the letter";
cin >> c;
lowercase = (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u');
Uppercase = (c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U');
if (!isalpha(c))
cout<< "Its not alphabet";
else if (lowercase || Uppercase)
cout << c << " is a vowel";
else
cout << c << " is a consonant";

return 0;
}

Output:

Enter the letter

f

f is a consonant

What is vowel in c++

A whole number that may be split into two equal whole numbers by two. Even numbers are zero, two, four, six, and eight. aaaaa There! You just made a vowel sound. An open sound is represented by a vowel, which is a letter. In the English language, there are six vowels: a, e, I o, u, and y. The letter Y is sometimes a vowel, like in the word narrative, but it may also be a consonant, as in the word yes.

What is consonant in c++

A consonant is a sound that is not a vowel in speech. It also refers to the letters of the alphabet that represent certain sounds: consonants include Z, B, T, G, and H. All non-vowel sounds, or their equivalent letters, are consonants: A, E, I, O, U, and occasionally Y are not consonants. H and T are consonants in the hat.

Write a c++ program to find out the given number is odd or even

Write a c++ program to find out the given number is odd or even. This program will print the odd or even number in result. By using this program we can check the number is odd or even using the c++ programming language for beginners.

#include <iostream>
using namespace std;
int main()
{
int n;
cout << "Enter the number";
cin >> n;
if ( n % 2 == 0)
cout << n << " is even";
else
cout << n << " is odd";
return 0;
}

Output:

Enter the number 45                                                                                                                                              

45 is odd

What is odd number in c++

Odd numbers are integers that, when divided by two, always leave a residue. These are integers of the type n = 2k + 1, where k is a positive integer. -5, -3, -1, 1, 3, 5, 7, and so on are examples of odd numbers.

What is even number in c++

a whole number that may be split into two equal whole numbers by two. Even numbers are zero, two, four, six, and eight.

How to implement if else statement in c++ programming

The conditional statements in C++ are as follows: If a particular condition is true, use if to specify a block of code to be run. If the same condition is false, use otherwise to define a block of code to run. If the initial condition is false, use else if to provide a new condition to test.

What is % or modulo operator in c++

The modulus operator (‘ percent ‘) is a built-in technique in the C and C++ languages that computes the remaining after completing integer division. You may also use the modulus operator to determine if an integer is odd or even. You can do so by asking for the remains of a number after it has been divided by two.

C++ program to swap two numbers using temporary variable

C++ program to swap two numbers using temporary variable. This program will change the numbers position using the C++. Swapping the numbers means it will interchange the number which are allocated in the c++ programming language.

#include <iostream>
using namespace std;
int main()
{
int a = 50, b = 10, temp,c;
cout << "Before" << c;
cout << "a = " << a << ", b = " << b << c;
temp = a;
a = b;
b = temp;
cout << "\nAfter" << c;
cout << "a = " << a << ", b = " << b << c;
return 0;
}

Output:

Before a = 50, b = 10
After a = 10, b = 50

What is temporary variable in c++ programming

A temporary variable is a variable in computer programming that has a limited lifetime and is used to retain data that will be deleted shortly or before it can be stored in a more permanent memory location. It’s generally stated as a local variable, or a variable with a local scope because it’s short-lived.

C++ program to print the sum of two numbers

C++ program to print the sum of two numbers. This program will add two numbers in result with the third variable in C++ to print the addition of two numbers in the CPP programming language. 

#include <iostream>
using namespace std;
int main()
{
int a, b, c;
cout << "Enter two integers: ";
cin >> a >> b;
c = a + b;
cout << a << " + " << b << " = " << c; 
return 0;
}

Output

Enter two integers:

45 45

45 + 45 = 90

What is operator in c++

Operators are a subset of functions that take one or more arguments and return a new value. Operators include things like addition (+), subtraction (-), multiplication (*), and so on. Variables and constants are operated on with the use of operators.

What is namespace in c++

You may specify the context in which names are defined by using namespace. A namespace, in essence, establishes a scope. C++ includes a standard library that contains common features like containers and algorithms that you’ll utilize in your programs.

C++ program to print the number

C++ program to print the number. This program will print the number in the C++ programming language. Here you can just print the program in cpp programming language. h, iostream is a C++ library that offers basic input and output services. The objects cin, cout, cerr, and clog are used by iostream to transfer data to and from the standard streams input, output, error (unbuffered), and log (buffered).

#include<stdio.h>
int main() 
{
std::cout << "45";
return 0;
}

Output:

45

What is headerfile in c++ program

Any C++ program begins with the main() function. It is the moment at which the program’s execution begins. When a C++ program is run, the main() function is the first thing that is called. The main() method is present in every C++ application.

How to implement return statement in c++

Once a function has completed its execution, it returns control to the caller function (or to the operating system if you transfer control from the main function). The calling function resumes execution where the call was initiated.

C++ program to print hello world

Write a program to print the hello world program in c++. This is a basic set of the program in C++ programming language for beginners. The display screen is usually the standard output device. The ostream class is represented by the C++ cout statement. It’s used to generate output for the standard output device, which is often a display screen.

#include<stdio.h>
int main() 
{
std::cout << "Hello world";
return 0;
}

Output:

Hello world

Difference between cin and cout in c++

cin is an input stream object that accepts input from files, consoles, and other input streams. cout is an output stream object that is used to display output. cin is an input statement, whereas cout is an output statement.

Return statement and how to impletement in c++ program

Returns control to the caller function once a function has completed its execution (or to the operating system if you transfer control from the main function). The calling function continues execution at the place where the call was made.