# C Program for Basic Calculator

July 27, 2020

Here is the C Program for the basic calculator. This is a simple calculator to do the basic arithmetics operations like addition, subtraction, multiplication, and division.

## C Program for Basic Calculator

``````
#include<stdio.h>
int main()
{
char yes;
int num1, num2, result, choice;

yes = 'y';
while(yes == 'y' || yes == 'Y')
{
printf("Enter First Integer Number: ");
scanf("%d", &num1);

printf("Enter Second Integer Number: ");
scanf("%d", &num2);

scanf("%d", &choice);

printf("\n");
switch(choice)
{
case(1):
result = num1 + num2;
printf("%d + %d = %d\n", num1, num2, result);
break;
case(2):
result = num1 - num2;
printf("%d - %d = %d\n", num1, num2, result);
break;
case(3):
result = num1 * num2;
printf("%d * %d = %d\n", num1, num2, result);
break;
case(4):
result = num1 / (float)num2;
printf("%d / %d = %d\n", num1, num2, result);
break;
default:
}

printf("\nRepeat Again? (Y/N): ");
scanf(" %c", &yes);
}

return 0;
}
``````

Output

```Enter First Integer Number: 45
Enter Second Integer Number: 30
2 for Subtraction
3 for Multiplication
4 for Division

45 + 30 = 75

Repeat Again? (Y/N): y
Enter First Integer Number: 65
Enter Second Integer Number: 30

2 for Subtraction
3 for Multiplication
4 for Division

65 - 30 = 35

Repeat Again? (Y/N): n

...Program finished with exit code 0
Press ENTER to exit console.
```

Tagged in: