同题....
只要有想法都可以说出来....一个也行....
海纳百川!~~
#include <stdio.h>
#include <string.h>
#include <conio.h>
#define STACK_SIZE 256
static unsigned char hex_tbl[16] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
int main() {
int stack[STACK_SIZE];
int *stkptr = stack;
int m = 0,n = 0;
/* Initialize stack */
memset(stack,0,sizeof(int)*STACK_SIZE);
printf("Please input a decimal value ? ");
scanf("%d",&m);
printf("Please input base value of conversion ? ");
scanf("%d",&n);
while(m) {
*stkptr++ = m % n;
m /= n;
}
printf("The result is ");
if(n == 16) {
while(--stkptr >= stack)
printf("%c",hex_tbl[*stkptr]);
printf("\n");
}
else {
while(--stkptr >= stack)
printf("%d",*stkptr);
printf("\n");
}
getch();
return 0;
}
前段日子刚好做过,你要十进制转几进制就转机进制。
#include<stdio.h>
int main()
{
int num,m,top=0;
char str[30];
scanf("%d",&num); /*输入数*/
scanf("%d",&m); /*输入进制*/
while(num)
{
if(num%m<10)
str[top]=num%m+'0';
else
str[top]=num%m-10+'A';
num=num/m;
top++;
}
while(--top>=0)
{
printf("%c",str[top]);
}
printf("\n");
return(0);
}
/*试试我的*/