C Program to Add Two Integers In this example, the user is asked to enter two integers. Then, the sum of these two integers is calculated and displayed on the screen. Jun 26, 2015 Write a C program to create menu driven calculator that performs basic arithmetic operations (add, subtract, multiply and divide) using switch case and functions. The calculator should input two numbers and an operator from user. It should perform operation according to the operator entered and must take input in given format. C Program to Add Two Numbers In this program, user is asked to enter two integers. Then, the sum of those two integers is stored in a variable and displayed on the screen. Download Add numbers program executable. In the expression (z = x + y), overflow may occur if the sum is greater than the maximum value that the variable z can store. Similarly, we can write a program that performs subtraction, multiplication, and division of two numbers. Add n Numbers in C. To add n numbers in C Programming, you have to ask to the user to enter the value of n (i.e., how many numbers he/she want to enter to all the numbers), then ask to enter n numbers to perform the addition of all the n numbers to display the result on the screen as shown here in the following program.
Selected Reading
C++ProgrammingServer Side Programming
Complex numbers are numbers that are expressed as a+bi where i is an imaginary number and a and b are real numbers. Some examples on complex numbers are −
A program to add complex numbers by passing structure to a function is given as follows −
Example
Write A Program To Add Two Numbers In Dev C++
The output of the above program is as follows −
In the above program, the structure complexNumber contains the real and imaginary parts of the complex number. This is given below −
The function addCN() takes two arguments of type complexNumber type and adds the real and imaginary parts of the two numbers. Then the added value is returned to the main() function. This is given below −
In the main() function, the values of the numbers are obtained from the user. This is given below −
The sum of the two numbers is obtained by the calling the addCN() function. Then the sum isprinted. This is given below −
C++ program to perform basic arithmetic operations of two numbers. Numbers are assumed to be integers and will be entered by the user.
Output of program:
When we divide two integers in C++ language we get integer result for example 5/2 evaluates to 2. As a general rule integer/integer = integer and float/integer = float or integer/float = float. So we convert denominator to float in our program, you may also write float in numerator. This is known as explicit conversion typecasting.
Addition Program In Dev C++
Here are few other related articles for you to read: