How to use C language to realize simple calculator function
This article mainly explains "how to use C language to achieve simple calculator functions". The explanation content in this article is simple and clear, easy to learn and understand. Please follow the ideas of Xiaobian slowly and deeply to study and learn "how to use C language to achieve simple calculator functions" together.
Simple calculator, simple addition, subtraction, multiplication and division function, select the corresponding operator output operator corresponding number, and then input we want to calculate the two numbers, the program will give the calculation results.
effect demonstration
Simple Calculator Code/* Simple Calculator name:zsh */ #include //simple calculator void menu() //operator display interface { printf("-----------------------------------\n");printf("Please enter your choice\n");printf("1. + \n"); printf("2. - \n"); printf("3. * \n"); printf("4. / \n"); printf("--------------------------------------------\n");}int main(){ int i = 0; int j = 0; int num = 0; //Save calculation results int select = 0; //store the selected operator do { menu(); //Print operator display interface scanf("%d", &select); //Enter operator number printf("Please enter the calculated value"); scanf("%d%d", &i, &j); //Enter operand value switch (select) { case 1: printf("%d+%d=%d\n", i, j, num=i+j); //addition break; case 2: printf("%d-%d=%d\n", i, j, num=i-j); //subtraction break; case 3: printf("%d*%d=%d\n", i, j, num=i*j); //multiplication break; case 4: printf("%d/%d=%d\n", i, j, num=i/j); //Division operation break; default: printf("Please select again! "); break; } } while(select); return 0; } Thank you for reading, the above is "how to use C language to achieve simple calculator function" content, after the study of this article, I believe that everyone on how to use C language to achieve simple calculator function this problem has a deeper understanding, the specific use of the situation also needs to be verified by practice. Here is, Xiaobian will push more articles related to knowledge points for everyone, welcome to pay attention!