| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 727 人关注过本帖
标题:试着写简单计算器的代码,但很多不会
取消只看楼主 加入收藏
air5116
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2014-11-1
结帖率:40%
收藏
已结贴  问题点数:16 回复次数:4 
试着写简单计算器的代码,但很多不会
#include <stdio.h>
#include <math.h>
int main() {
    int z,i,j;
    while (1) {
        printf("                       *********************\n");
        printf("                       **     1.加法运算     **\n");
        printf("                       **     2.减法运算     **\n");
        printf("                       **     3.乘法运算      **\n");
        printf("                       **     4.除法运算      **\n");
        printf("                       **     5.求余运算     **\n");
        printf("                       **     6.累加运算     **\n");
        printf("                       **     7.阶乘运算      **\n");
        printf("                       **     8.退出     **\n");
        printf("                       *********************\n");
        printf("                            请选择功能:");
        scanf("%d",&z);
        printf("请输入操作数:");
        scanf("%d%c%d",&i,&j);
        switch(z) {
         case 1:printf("=%d",i+j);break;
         case 2:printf("=%d",i-j);break;
         case 3:printf("=%d",i*j);break;
         case 4:
         if(j==0)
         {printf("分母不能为零");  break;  }
         printf("=%d",i/j);break;
         default:printf("无解");break;
         case 5:printf("=%d",i%j);break;
        }
    }
}
搜索更多相关主题的帖子: 计算器 include 
2014-11-08 14:44
air5116
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2014-11-1
收藏
得分:0 
都计算不了的,谁能指点一下
2014-11-08 14:45
air5116
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2014-11-1
收藏
得分:0 
回复 2 楼 air5116
#include <stdio.h>
#include <math.h>
int main() {
   int z,i,j;
    while (1) {
        printf("                       *********************\n");
        printf("                       **     1.加法运算     **\n");
        printf("                       **     2.减法运算     **\n");
        printf("                       **     3.乘法运算      **\n");
        printf("                       **     4.除法运算      **\n");
        printf("                       **     5.求余运算     **\n");
        printf("                       **     6.累加运算     **\n");
        printf("                       **     7.阶乘运算      **\n");
        printf("                       **     8.退出     **\n");
        printf("                       *********************\n");
        printf("                            请选择功能:");
        scanf("%d",&z);
        printf("请输入操作数:");
        scanf("%d%*c%d",&i,&j);
        switch(z) {
         case 1:printf("=%d",i+j);break;
         case 2:printf("=%d",i-j);break;
         case 3:printf("=%d",i*j);break;
         case 4:
         if(j==0)
         {printf("分母不能为零");  break;  }
         printf("=%d",i/j);break;
         default:printf("无解");break;
         case 5:printf("=%d",i%j);break;
         case 6:            /*累加计算*/
         printf("请输入两个整数");
         scanf("%d%d",&c,&d);
         intresult=addnumber(i,j);
         printf("%d-%d的累加计算结果是:%d\n",i,j,intresult);break;
          case 7:   //阶乘计算
    {
     printf("请输入一个大于0小于10的整数字");
     scanf("%d",&i);
     if(i<0||i>10)
     {
      printf("请输入一个大于0小于10的整数字,数据错误。\n");
      break;
     }
     intresult=factor(i);
     printf("%d的阶乘计算结果是:%d\n",i,intresult);
     break;
    }
        }
    }
}   
这样又怎样改啊
2014-11-08 17:07
air5116
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2014-11-1
收藏
得分:0 
运行不了,谁能帮我修改下。。。。
#include "stdio.h"
#include "math.h"
void main()
void menu()
{
        printf("                       *********************\n");
        printf("                       **     1.加法运算     **\n");
        printf("                       **     2.减法运算     **\n");
        printf("                       **     3.乘法运算      **\n");
        printf("                       **     4.除法运算      **\n");
        printf("                       **     5.求余运算     **\n");
        printf("                       **     6.累加运算     **\n");
        printf("                       **     7.阶乘运算      **\n");
        printf("                       **     8.退出     **\n");
        printf("                       *********************\n");
        printf("                            请选择功能:");  
}
void add()
{
    float a,b;
    printf("请输入两个要计算的数:"\n);
    scanf("%f%f",&a,&b);
    printf("%f+%f=%f\n",a,b,a+b);
}
void sud()
   {
       float a,b;
   printf("请输入两个要计算的数:"\n);
    scanf("%f%f",&a,&b);
    printf("%f-%f=%f\n",a,b,a-b);
   }
void mul()
{
   float a,b;
   printf("请输入两个要计算的数:"\n);
    scanf("%f%f",&a,&b);
    printf("%f*%f=%f\n",a,b,a*b);
    }
void div()
{
   float a,b;
   printf("请输入两个要计算的数:"\n);
    scanf("%f%f",&a,&b);
    if(b==0)
    printf("无解\n");
    else
    printf("%f/%f=%f\n",a,b,a/b);
}
void demain()
{
    int a,b;
    printf("请输入两个要计算的数:"\n);
    scanf("%d%d",&a,&b);
    if(b==0)
    printf("无解\n");
    else
    printf("%d%%d=%d\n",a,b,a%b);
}
void m_to_n()
{
    int m,n,i=0,sum=0;
    printf("请输入累加的首项和尾项:\n");
    scanf("%d%d",&n,&m);
    if(n<m)
    printf("无解\n");
    else  
{
    for(i=n;i<=m;i++)
    sum+=i;
    printf("%d+.....+%d=%d\n",n,m,sum);
}
}
void factor()
{
    int i,n,sum;
    printf("请输入要计算的数:"\n);
    scanf("%d",&n);
    if(n<=0)
    printf("无解\n");
    else
{
    for(i=1;sun=1;i<=n;i++)
    sum*=i;   
    printf("%d!=%d\n"n,sum);
}
}
2014-11-09 15:15
air5116
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2014-11-1
收藏
得分:0 
前面的很多头文件没复制上来,下面打代码确实存在很多错误,现在修改过来可以计算啦,谢谢
2014-11-09 22:18
快速回复:试着写简单计算器的代码,但很多不会
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018551 second(s), 10 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved