Happy Codings - Programming Code Examples
Html Css Web Design Sample Codes CPlusPlus Programming Sample Codes JavaScript Programming Sample Codes C Programming Sample Codes
CSharp Programming Sample Codes Java Programming Sample Codes Php Programming Sample Codes Visual Basic Programming Sample Codes

C++ > Mathematics Code Examples

Addition Subtraction Multiplication Division

/* Addition Subtraction Multiplication Division To perform addition, subtraction, multiplication and division of any two numbers in C++ Programming, you have to ask to the user to enter the two number and then ask to enter the operator to perform the particular mathematical operation (addition, subtraction, multiplication, and division) and display the result on the screen. Following C++ program ask to user to enter the two number and perform addition, subtraction, multiplication and division on the two entered number: C++ Program - Addition, Subtraction, Multiplication, Division */ #include<iostream.h> #include<conio.h> void main() { clrscr(); int a, b, res; cout<<"Enter two number :"; cin>>a>>b; res=a+b; cout<<"\nAddition = "<<res; res=a-b; cout<<"\nSubtraction = "<<res; res=a*b; cout<<"\nMultiplication = "<<res; res=a/b; cout<<"\nDivision = "<<res; getch(); }
Standard Input Stream (cin) in C++ Programming Language
The cin object is used to accept input from the standard input device i.e. keyboard. It is defined in the iostream header file. C++ cin statement is the instance of the class istream and is used to read input from the standard input device which is usually a keyboard. The extraction operator(>>) is used along with the object cin for reading inputs. The extraction operator extracts the data from the object cin which is entered using the keyboard. The "c" in cin refers to "character" and "in" means "input". Hence cin means "character input". The cin object is used along with the extraction operator >> in order to receive a stream of characters.
#include Directive in C++ Programming Language
#include is a way of including a standard or user-defined file in the program and is mostly written at the beginning of any C/C++ program. This directive is read by the preprocessor and orders it to insert the content of a user-defined or system header file into the following program. These files are mainly imported from an outside source into the current program. The process of importing such files that might be system-defined or user-defined is known as File Inclusion. This type of preprocessor directive tells the compiler to include a file in the source code program.
main() Function in C++ Programming Language
A program shall contain a global function named main, which is the designated start of the program in hosted environment. main() function is the entry point of any C++ program. It is the point at which execution of program is started. When a C++ program is executed, the execution control goes directly to the main() function. Every C++ program have a main() function.
Assignment Operators in C++ Programming Language
As the name already suggests, these operators help in assigning values to variables. These operators help us in allocating a particular value to the operands. The main simple assignment operator is '='. We have to be sure that both the left and right sides of the operator must have the same data type. We have different levels of operators. Assignment operators are used to assign the value, variable and function to another variable. Assignment operators in C are some of the C Programming Operator, which are useful to assign the values to the declared variables. Let's discuss the various types of the assignment operators such as =, +=, -=, /=, *= and %=. The following table lists the assignment operators supported by the C language:
getch() Function in C++ Programming Language
The getch() is a predefined non-standard function that is defined in conio.h header file. It is mostly used by the Dev C/C++, MS- DOS's compilers like Turbo C to hold the screen until the user passes a single value to exit from the console screen. It can also be used to read a single byte character or string from the keyboard and then print. It does not hold any parameters. It has no buffer area to store the input character in a program. The getch() function does not accept any parameter from the user. It returns the ASCII value of the key pressed by the user as an input.
clrscr() Function in C++ Programming Language
It is a predefined function in "conio.h" (console input output header file) used to clear the console screen. It is a predefined function, by using this function we can clear the data from console (Monitor). Using of clrscr() is always optional but it should be place after variable or function declaration only. It is often used at the beginning of the program (mostly after variable declaration but not necessarily) so that the console is clear for our output.
Standard Output Stream (cout) in C++ Programming Language
The cout is a predefined object of ostream class. It is connected with the standard output device, which is usually a display screen. The cout is used in conjunction with stream insertion operator (<<) to display the output on a console. On most program environments, the standard output by default is the screen, and the C++ stream object defined to access it is cout. The "c" in cout refers to "character" and "out" means "output". Hence cout means "character output". The cout object is used along with the insertion operator << in order to display a stream of characters.
Arithmetic Operators in C++ Programming Language
Arithmetic Operator is used to performing mathematical operations such as addition, subtraction, multiplication, division, modulus, etc., on the given operands. For example: 6 + 3 = 9, 5 - 3 = 2, 3 * 4 = 12, etc. are the examples of arithmetic operators. Let's discuss the different types of Arithmetic Operators in the C programming. Plus Operator is a simple Plus (+) Operator used to add two given operands. We can use Plus Operator with different data types such as integer, float, long, double, enumerated and string type data to add the given operand. The minus operator is denoted by the minus (-) symbol. It is used to return the subtraction of the first number from the second number. The data type of the given number can be different types, such as int, float, double, long double, etc., in the programing language.
This program illustrates a simple if-else statement.
Make the result of integer division a float
Deque push front - Inserts object x at the front of the deque container.
Overloaded string concatenation operator
The find algorithm locates the first element in the range [first, last)
Generate All Possible Combinations of List
Algorithm takes the input of 'n' data element and prints all 'possible combination'. For that, it maintains a boolean 'Array of Length' "n". If the corresponding boolean value is true, then
Provide std::generate_n with predicate
C++ Program to Demonstrate for loop
Find The Position of A Point With Respect
This is a C++ Program to check whether point lies above, below or on the line. For example, the equation of the line connecting points (2, 2) and (4, 5) is -3x + 2y + 2 = 0. The point (6, 3)
When there is an if statement inside another if statement then it is called the nested if statement.
Binary Search - Returns a boolean value indicating whether or not val was found.
Set showpos flag for decimal