C language: Use the parameters of the main function to implement an integer computer.

Source: Internet
Author: User

#include <stdio.h> #include <stdlib.h> #include <assert.h>int calculator (INT&NBSP;NUM1, &NBSP;CHAR&NBSP;*P,&NBSP;INT&NBSP;&NBSP;NUM2) {     if  (p ==  "-a")           return num1 + num2;      else if  (p ==  "-S")            return num1 - num2;     else if  (p ==  "-M")           return num1 * num2;      else if  (p ==  "-D")            return num1 / num2;     else           return -1;} Int main () {     char a;     char *p = &a;     int num1 = 0;     &NBSP;INT&NBSP;NUM2&NBSP;=&NBSP;0;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;SCANF ("%d%c%d",  &num1, &a, &NBSP;&AMP;NUM2);          if  (a ==  ' + ')           p =  "-a";     //"-A" Option to perform addition      else if  (a ==  '-')            p =  "-S";     //"-S" option to perform subtraction       else if  (a ==  ' * ')           p =   "-M";     //"-M" option to perform multiplication      else if  (a ==   '/')           p =  '-d ';     //"-d" option to perform division      else          p =  ';   '              int ret =  Calculator (num1, p, num2);      printf ("%d%c%d=%d\n",  num1, a,  num2, ret);      system ("Pause");     return  0;}

C language: Use the parameters of the main function to implement an integer computer.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.