| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 275 人关注过本帖
标题:请各位指教输出不正常问题出在哪里,谢谢。
只看楼主 加入收藏
aiyameili
Rank: 2
等 级:论坛游民
帖 子:16
专家分:14
注 册:2013-8-25
结帖率:100%
收藏
 问题点数:0 回复次数:1 
请各位指教输出不正常问题出在哪里,谢谢。
关于取模,我用的是VC6.0:
代码:
#include<stdio.h>
int main(void)
{
    printf("11/5 is %d and 11%5 is %d\n",11/5,11%5);
    printf("11/-5 is %d and 11%-2 is %d\n",11/-5,11%-2);
    printf("-11/-5 is %d and -11%-5 is %d\n",-11/-5,-11%-5);
    printf("-11/5 is %d and -11%5 is %d\n",-11/5,-11%5);
    return 0;
}
运行结果如下:
11/5 is 2 and 11 is 1
11/-5 is -2 and 11 is 1
-11/-5 is 2 and -11 is -1
-11/5 is -2 and -11 is -1
为什么不是:
11/5 is 2 and 11%5 is 1
11/-5 is -2 and 11%-2 is 1
-11/-5 is 2 and -11%-5 is -1
-11/5 is -2 and -11%5 is -1
我该了代码后:
#include<stdio.h>
int main(void)
{
    printf("11/5 is %d and 11%%5 is %d\n",11/5,11%5);
    printf("11/-5 is %d and 11%%-2 is %d\n",11/-5,11%-2);
    printf("-11/-5 is %d and -11%%-5 is %d\n",-11/-5,-11%-5);
    printf("-11/5 is %d and -11%%5 is %d\n",-11/5,-11%5);
    return 0;
}
结果却变成:
11/5 is 2 and 11÷5 is 1
11/-5 is -2 and 11÷-2 is 1
-11/-5 is 2 and -11÷-5 is -1
-11/5 is -2 and -11÷5 is -1

实在搞不懂啥原因啊,请各位指教指教,先谢谢了。
已找到原因,输出显示的%太小,自己误看成÷了,实属不该啊,以后仔细点。

[ 本帖最后由 aiyameili 于 2014-3-21 22:12 编辑 ]
搜索更多相关主题的帖子: include return 
2014-03-21 21:58
aiyameili
Rank: 2
等 级:论坛游民
帖 子:16
专家分:14
注 册:2013-8-25
收藏
得分:0 
回复 楼主 aiyameili
已找到原因,输出显示的%太小,自己误看成÷了,实属不该啊,以后仔细点。
2014-03-21 22:10
快速回复:请各位指教输出不正常问题出在哪里,谢谢。
数据加载中...
 
   



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

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