Chinaunix首页 | 论坛 | 博客
  • 博客访问: 172464
  • 博文数量: 56
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 550
  • 用 户 组: 普通用户
  • 注册时间: 2014-11-17 16:14
文章分类

全部博文(56)

文章存档

2015年(24)

2014年(32)

我的朋友

分类: C/C++

2014-12-22 11:58:50


点击(此处)折叠或打开

  1. #include <stdio.h>

  2. static void base_convert(void)
  3. {
  4.     int i = 0;
  5.     int num,base;
  6.     int n[128];

  7.     printf("Please enter the converted num:");
  8.         scanf("%d",&num);
  9.     printf("Please enter the base:");
  10.         scanf("%d",&base);
  11.     do
  12.     {
  13.         n[i++] = num%base;
  14.         num = num/base;
  15.     }while(num !=0);
  16.     
  17.     for(i--;i>=0; i--)
  18.     {    if(n[i]>=10)
  19.             printf("%c",n[i]-10+'A');    
  20.         else printf("%d",n[i]);
  21.     }
  22.     printf("\n");
  23. }

  24. int main()
  25. {
  26.     base_convert();    
  27. }

阅读(1010) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~