//实现计算机功能的程序 a program which can work the functions as a #include //头文件#include void menu();//声明部分void add();void sub();void mul();void div();void remain();void add_n_to_m();void factor();main(){ int i; while(1) { system("cls");//清屏功能 menu(); printf("choose function:"); scanf("%d",&i); switch(i) { case 1:add();getch();break;//调用部分 case 2:sub();getch();break; case 3:mul();getch();break; case 4:div();getch();break; case 5:remain();getch();break; case 6:add_n_to_m();getch();break; case 7:factor();getch();break; case 8: exit(0);break; } }}//以下是自己定义的函数void menu()//菜单{ printf("+====my counter===+\n"); printf("+功能如下: +\n"); printf("+ 加法 +\n"); printf("+ 减法 +\n"); printf("+ 乘法 +\n"); printf("+ 除法 +\n"); printf("+ 求余 +\n"); printf("+ 从n到m的和+\n"); printf("+ 阶乘 +\n"); printf("+ 退出 +\n"); printf("+=================+\n");}void add()//加法运算{ double a,b; printf("input two numbers:"); scanf("%lf%lf",&a,&b); printf("%lf+%lf=%lf\n",a,b,a+b);}void sub()//减法运算{ double a,b; printf("input two numbers:"); scanf("%lf%lf",&a,&b); printf("%lf-%lf=%lf\n",a,b,a-b);}void mul()//乘法运算{ double a,b; printf("input two numbers:"); scanf("%lf%lf",&a,&b); printf("%lf*%lf=%lf\n",a,b,a*b);}void div()//除法运算{ double a,b; printf("input two numbers:"); scanf("%lf%lf",&a,&b); if(b==0)//被除数不能为0 printf("error\n"); else printf("%lf/%lf=%lf\n",a,b,a/b);}void remain()//求余运算{ int a,b; printf("input two numbers:"); scanf("%d%d",&a,&b); if(b==0)//被除数不能为0 printf("error\n"); else printf("%d%%%d=%d\n",a,b,a%b);}void add_n_to_m()//累加{ int m,n,i=0,s=0; printf("input n and m:"); scanf("%d%d",&n,&m); if(n>m) printf("\n");//条件限制 else { for(i=n;i<=m;i++) s+=i; printf("%d++%d=%d\n",n,m,s); }}void factor()//阶乘{ int n,i,s; printf("input a number:"); scanf("%d",&n); if(n<=0) printf("\n");//条件限制 else { for(i=1,s=1;i<=n;i++) s*=i; printf("%d!=%d\n",n,s); }}