In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "the methods and steps of C language using function pointer array to realize calculator function". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn the methods and steps of C language using function pointer array to realize calculator function.
Let's review the concept first:
Pointer array-the array where pointers are stored
Function pointer-A pointer that stores the address of a function
Array of function pointers-an array of function pointers
Next, let's talk about the functions of the calculator to be made this time:
1.add-addition
2.sub-subtraction
3.mul-multiplication
4.div-division
0.exit-exit
Specifically, it is explained through the code:
(1) first write a menu program, and print the menu first when running the program.
Void menu () {printf ("*\ n"); printf ("* 1.add *\ n"); printf ("* 2.sub *\ n"); printf ("* 3.mul *\ n") Printf ("* 4.div *\ n"); printf ("* 0.exit *\ n"); printf ("*\ n");}
(2) write four functions about addition, subtraction, multiplication and division.
Int Add (int x, int y) {return x + y;} int Sub (int x, int y) {return x-y;} int Mul (int x, int y) {return x * y;} int Div (int x, int y) {return x / y;}
(3) write the main function, define input as the number you want to enter to select the function; define x and y as the operands you want to enter; and then call the menu function menu () in the main program.
Int main () {int x = 0; int y = 0; int input = 0; menu ();}
(4) use the do while loop, and the if else statement to establish the rules, exit the loop if the input input is 0, while (input) represents a non-zero input will continue the cycle; if the input between 1 and 4 corresponds to the calculator menu function, then you need to enter two numbers; if beyond this range then re-cycle.
Int main () {int x = 0; int y = 0; int input = 0; menu (); do {printf ("Please select what you want to do:\ n"); scanf ("% d", & input); if (input = = 0) {printf ("quit calculator!\ n");} else if (input > = 1 & input = 1 & input
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.