In addition to Weibo, there is also WeChat
Please pay attention

WeChat public account
Shulou
2025-12-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "how to use C language to achieve calculator function". The content of the explanation in this article is simple and clear, and it is easy to learn and understand. let's study and learn how to use C language to realize calculator function.
The details are as follows
The code is as follows:
# include / / C language to write a calculator program ^ _ ^ void Counter1 (int a minute int bjorchar op); / / function declaration! Void Counter2 (double crecinct double djinchar op), void Show_Sum1 (int arecrowchar op,int b), void Show_Sum2 (double creceddje char op,double sum), int Add (int adjint b), int Sub (int apentry int b), int Mul (int adjint b), double Div (double arech double b), int main () {int aql0 recorder bacco / initialize double censor 0. 0 and 0. 0 char op='#'; char ch='#'; int choi=0; Do {printf ("Please enter data: (you want to enter 1 using the addition, subtraction and multiplication function, and 2 using the division function)\ n"); scanf ("% d", & choi); if (choi==1) {printf ("format of input data: numeric operator values\ n"); scanf ("% d% c% d", & a); / / Don't forget to take the address operator! Fflush (stdin); / / is used to clean the cache! (execution input ends with'\ n' representing input, and'\ n' stays in the cache, so the cache should be emptied first in case the ch receives the character and ends the loop!) Counter1 (a lf bforme op);} else if (choi==2) {printf ("format of input data: numeric operator values\ n"); scanf ("% lf% c% lf", & crecedomain); / / Don't forget to take the address operator! Fflush (stdin); / / is used to clean the cache! (execution input ends with'\ n' representing input, and'\ n' stays in the cache, so the cache should be emptied first in case the ch receives the character and ends the loop!) Counter2 (cquoise op);} printf ("do you want to continue? (YPJ N):\ n"); ch=getchar (); / / input characters Y (y) or N (n)} while (ch=='Y' | | ch=='y'); return 0;} void Counter1 (int adirection int bdirection char op) {int sum=0; int optag=true;// in case the denominator is zero (an error occurs) or the input error character still calls the Show_Sum () function for output. Switch (op) {case'+': sum=Add (AMaginb); break; case'-': sum=Sub (Arecom b); break; case'*': sum=Mul (Arecom b); break; default: {printf ("operator error! \ n "); optag=false; break;}} if (optag) Show_Sum1;} void Counter2 (double c magnificent double djejinchar op) {double sum=0.0; int optag=true;// in case the denominator is zero (there is an error) or the input error character still calls the Show_Sum () function for output. Switch (op) {case'/': {if (dashes zero) {optag=false; printf ("Divisor is zero, an error occurred! \ n ");} else sum=Div (cPowerd); break;} default: {printf (" operator error! \ n "); optag=false; break;}} if (optag) Show_Sum2;} void Show_Sum1 (int arech char op,int breco int sum) {printf ("% d% c% dice% d ", apcrine bpenny sum); / / output the calculation result} void Show_Sum2 (double cmagin double dde op,double sum) {printf ("% .4f% c% .4f =% .4f ", cMagol opMagee dmam sum) } int Add (int a minus int b) {return aqinb; / / plus} int Sub (int a minus int b) {return aripb; / / minus} int Mul (int a minus int b) {return aqumb; / / multiply} double Div (double a dint b) {return ahand b; / / division}
Ps: those that should be noted or prone to problems have been marked with comments in the code area.
Thank you for your reading, the above is the content of "how to use C language to achieve calculator function". After the study of this article, I believe you have a deeper understanding of how to use C language to achieve calculator function. the specific use of the situation also needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.

The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope





About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.