Classic C language program] Realize a simple calculator in C language

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.hheader files to get the input and output functions, and stdbool.hheader files to use the boolean type. In addition, we also need to define some global variables, such as num1and num2to store the number entered by the user, and operatorto store the operator selected by the user.

#include <stdio.h>
#include <stdbool.h>

double num1, num2;
char operator

Guess you like

Origin blog.csdn.net/wellcoder/article/details/132374580