Classic C language program] Realize a simple calculator in C language
In this article, I will show you how to write a simple calculator program in C language. This calculator program can perform basic math operations such as addition, subtraction, multiplication and division. We will walk through the process of writing this program step by step and provide the corresponding source code.
First, let's define the header files and global variables needed by the program. We'll use stdio.h
header files to get the input and output functions, and stdbool.h
header files to use the boolean type. In addition, we also need to define some global variables, such as num1
and num2
to store the number entered by the user, and operator
to store the operator selected by the user.
#include <stdio.h>
#include <stdbool.h>
double num1, num2;
char operator