| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 458 人关注过本帖
标题:輸出結果不是二進制??
只看楼主 加入收藏
slioplark
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2013-8-20
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:5 
輸出結果不是二進制??
#include<stdlib.h>
#include<stdio.h>

int main(){

  long int decimalNumber,quotient;
  int binaryNumber[100],i=1,j;

  printf("Enter any decimal number: ");
  scanf("%d",&decimalNumber);

  quotient = decimalNumber;

  if(quotient!=0){
      binaryNumber[i++]= quotient % 2;
      quotient = quotient / 2;
  }

  printf("Equivalent octal value of decimal number %d: ",decimalNumber);
  for(j = i -1 ;j> 0;j--)
      printf("%d",binaryNumber[j]);

  system("pause");
  return 0;
}

-----------------------------------------------------------------------
請各位幫忙看一下 為什麼輸出的結果不是二進制??
感謝各位高手的幫忙!!!
搜索更多相关主题的帖子: quotient include system number return 
2013-08-20 10:37
wp231957
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:神界
等 级:贵宾
威 望:423
帖 子:13688
专家分:53332
注 册:2012-10-18
收藏
得分:5 
二进制一般都用字符串来表示的

DO IT YOURSELF !
2013-08-20 10:41
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:528
帖 子:9007
专家分:53942
注 册:2011-1-18
收藏
得分:5 
long类型对应的是%ld
if(quotient!=0) 应该是 while(quotient!=0)

从1开始计数是很恶心的行为
2013-08-20 10:44
韶志
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:斗气大陆
等 级:贵宾
威 望:44
帖 子:2223
专家分:13592
注 册:2013-3-22
收藏
得分:5 
if(quotient!=0)
把这一语代码中的if 改为  while  就行了

三十年河东,三十年河西,莫欺少年穷!
2013-08-20 11:58
molubingxue
Rank: 1
来 自:浙江
等 级:新手上路
帖 子:7
专家分:8
注 册:2013-8-21
收藏
得分:0 
楼上正解

努力就有收获。
可有几人真正理解,做到。
真理在身边,忽略了,是你的错
2013-08-21 20:53
jg658237
Rank: 7Rank: 7Rank: 7
来 自:青藏高原
等 级:黑侠
帖 子:224
专家分:529
注 册:2013-8-8
收藏
得分:5 
#include<stdlib.h>
#include<stdio.h>

int main(){

  long int decimalNumber,quotient;
  int binaryNumber[100],i=1,j;

  printf("Enter any decimal number: ");
  scanf("%d",&decimalNumber);

  quotient = decimalNumber;

  while(quotient!=0)
  {
      binaryNumber[i++]= quotient % 2;
      quotient = quotient / 2;
  }

  printf("Equivalent octal value of decimal number %d: \n",decimalNumber);
  for(j = i -1 ;j> 0;j--)
      printf("%d\n",binaryNumber[j]);

  system("pause");
  return 0;                       我帮你修改了,你现在看一下吧
}

武功再高也怕菜刀.
2013-08-22 15:43
快速回复:輸出結果不是二進制??
数据加载中...
 
   



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

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