标题:#include<stdio.h>
只看楼主
m1005010117
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2011-4-26
结帖率:33.33%
 问题点数:0 回复次数:2 
#include<stdio.h>
请问这个程序哪里错了啊   

#include<stdio.h>
int main()
{
    float a,b;
    char coperator;
    printf("please type in your expression(a+b)\n");
    scanf("%f %c %f",&a,&coperator,&b);
    switch(coperator){
        case'+':printf("%.2f\n",a+b);break;
        case'-':printf("%.2f\n",a-b);break;
        case'*':printf("%.2f\n",a*b);break;
        case'/':if(b==0) printf("division by zero error found\n");
                else printf("=%.2f\n",a/b);break;
        case'%':printf("%%",a%b);break;
        default:printf("错误\n");break;}
            return 0;

}
搜索更多相关主题的帖子: please 
2011-04-26 17:59
qq1023569223
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:湖南科技大学
等 级:贵宾
威 望:26
帖 子:2753
专家分:13404
注 册:2010-12-22
得分:0 
程序代码:
#include<stdio.h>
int main()
{
    float a,b;
    char coperator;
    printf("please type in your expression(a+b)\n");
    scanf("%f %c %f",&a,&coperator,&b);
  
   switch(coperator)
   {
        case'+':printf("=%.2f\n",a+b);break;
        case'-':printf("=%.2f\n",a-b);break;
        case'*':printf("=%.2f\n",a*b);break;
        case'/':if(b==0) printf("=division by zero error found\n");
                else printf("=%.2f\n",a/b);  break;
        //case'%':printf("=%.2f\n",a%b);break; //%求余不能作用于浮点数
        default:printf("错误\n");break;
   }
            return 0;

} 

   唯实惟新 至诚致志
2011-04-26 18:05
laoyang103
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:内蒙古包头
等 级:贵宾
威 望:19
帖 子:3082
专家分:11056
注 册:2010-5-22
得分:0 
恩  浮点数要先转整数然后再求余  不过这经常会违背你的本意

                                         
===========深入<----------------->浅出============
2011-04-26 19:27



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-337983-1-1.html




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

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