标题:合法输入和非法输入
取消只看楼主
ychf890225
Rank: 4
等 级:业余侠客
帖 子:85
专家分:221
注 册:2010-4-15
结帖率:100%
已结贴  问题点数:10 回复次数:3 
合法输入和非法输入
程序代码:
#include<stdio.h>
#include<math.h>

main()
{
    double a=0.0;
    int b;
    double c;
  
    printf("This project is used to separate the integer and decimal part of a  number\n");
    printf("please input the number:\n");
    scanf("%lf",&a);

    if (a>=0.0)
        {
            b=(int)floor(a);
            printf("the integer of the number you input is %d\n",b);
        }
    else if(a<0.0)
        {
            b=(int)ceil(a);
            printf("the integer of the number you input is %d\n",b);
        }
    else
        printf("Please check the number you input");

    c=a-b;
    printf("the decimal part of the number you input is %g\n",c);

    return 0;
}
哪位高手看看第二十八和二十九行该怎么写,谢谢了

[ 本帖最后由 ychf890225 于 2010-4-22 13:21 编辑 ]
搜索更多相关主题的帖子: 输入 合法 
2010-04-22 13:08
ychf890225
Rank: 4
等 级:业余侠客
帖 子:85
专家分:221
注 册:2010-4-15
得分:0 
朋友们 帮忙看看 谢谢了
2010-04-22 13:33
ychf890225
Rank: 4
等 级:业余侠客
帖 子:85
专家分:221
注 册:2010-4-15
得分:0 
回复 2楼 ychf890225
怎么看看当输入非法数据 如字符的时候给个提示
2010-04-22 18:29
ychf890225
Rank: 4
等 级:业余侠客
帖 子:85
专家分:221
注 册:2010-4-15
得分:0 
回复 4楼 hahayezhe
谢谢  就是不明白怎么排除 我做的时候直接输个字符就把我弄晕了
不知道怎么排除
2010-04-22 20:06



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




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

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