# Arithmetic Operations or Simple Calculator in C/C++.

## Arithmetic Operations or Simple Calculator in C/C++.

C/C++ allows us to perform basic arithmetic operations such as addition, multiplication, division, subtraction, etc. We can write separate programs to perform all the operations separately or we can write a single program which will perform all the arithmetic operations. Let’s see how we can perform arithmetic operations or make a simple calculator in C/C++.

To perform arithmetic operations we will require arithmetic operators. Arithmetic operators in c are +,-,*,/,%. So let’s see the code now.

## Code –

``````//Arithmetic Operations or simple calculator using C

#include<stdio.h>

int main()
{
int a,b;
printf("Enter value for a and b:");
scanf("%d%d",&a,&b);

printf("\nSubtraction is:%d",a-b);
printf("\nMultiplication is:%d",a*b);
printf("\nDivision is:%d",a/b);
printf("\nRemainder is:%d",a%b);

return 0;
}``````
``````//Arithmetic Operations or simple calculator using C++

#include<iostream>

using namespace std;
int main()
{
int a,b;
cout<<"\nEnter value for a and b:";
cin>>a>>b;

cout<<"\nSubtraction is:"<<a-b;
cout<<"\nMultiplication is:"<<a*b;
cout<<"\nDivision is:"<<a/b;
cout<<"\nRemainder is:"<<a%b;

return 0;
}``````

## Output –

### Program parts –

1. #include is a pre-processor directive. It is used to include header files.
2. stdio/iostream is header file which has certain commands that c/c++ supports. E.g. return, main, etc.
3. conio is a header file which is use to include commands like clrscr(),getch() in the code.
4. .h is an extension for header file.
5. int is data type. It indicates that the program returns a value.
6. main() is main function that indicates the compiler that the user written programs starts from here.
7. int is datatype used to declare variables of integer type.
8. a,b are varibale names.
9. print/cout is the keyword used to print a message.
10. scanf/cin is the keyword used to store values.
12. a-b calculates subtraction.
13. a*b calculates multiplication.
14. a/b calculates division.
15. a%b calculates remainder.
16. return statement is use to return a value. If any error occurs the program will return 0.

### Explanation –

Program is simply going to perform arithmetic operations on the entered values. The program will check the header files and then it will enter the main function. In main function it will declare variables a and b and then perform respective operations.

### Conclusion –

So this is how we perform arithmetic operations or simple calculator in C/C++. There are many methods in which we can perform mathematical operations or create a simple calculator. Tell us in comment section below about your logics and what other programs you want us to upload.

For more such posts do visit ErrorFreeProgram. Follow us on instagram to get daily updates.

View All Posts