进制转换问题
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;
}
#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;
}
相关文章推荐
- java中的进制转换问题
- 进制转换问题
- 神奇的位运算——进制转换问题(16转8)
- 复试训练——数学问题—— 进制转换
- 进制转换问题
- 问题一百四十一:进制转换
- PHP 进制转换 dechex 无法正确计大数字问题
- java-自定义的进制转换-可以处理缩短uuid长度的问题
- 07_整数类型_进制转换_编程中的L问题
- 进制转换问题(c++)
- 进制转换问题
- 进制转换问题
- JS中字符问题(二进制/十进制/十六进制之间的转换),颜色进制转换
- C语言整数类型及printf格式化输出问题总结复习及进制转换的简单实现
- 黑马程序员5--进制转换问题
- 栈,进制转换(用数组输出) 有个问题不明白,请高人指点
- poj 3191(-2)进制转换问题。
- 基本数据类型的进制转换问题
- 【Loadrunner】解决进制转换问题
- 进制转换中pow()函数的问题