您的位置:首页 > 其它

进制转换问题

2018-03-18 10:01 162 查看
#include<stdio.h>
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
 char st1[1000],st2[1000];
 long long n,a,b,c,t=0,m=0,r;
 while(cin>>n>>r)
{
 m=0;
 t=0;
 if(n<0)
 {
  m=1;
  n=-n;
 }
 memset(st1,0,sizeof(st1));
 if(n==0)
 printf("0");
 while(n!=0)
  {
   
   b=n%r;
   //st1[t++]=n%r+48;
   if(b>=10)
   st1[t++]=b+55;
   else
   st1[t++]=b+48;
   n/=r;
   }
   if(m==1)
   printf("-");
  for(int i=t-1;i>=0;i--)
   {
    printf("%c",st1[i]);
   }
  printf("\n");
}
 return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: