[ create a new paste ] login | about

Link: http://codepad.org/0BMeG9w5    [ raw code | output | fork ]

C, pasted on Jul 11:
#include <stdio.h>
void            conv_base(int, int, char *);

int
main(void)
{
  char            x[20] = "", *p = x;
  int             dec, base;

  printf("dec base = ");
  scanf("%d %d", &dec, &base);
  x[0] = '\0';
  conv_base(dec, base, x);
  while (*p)
    p++;
  while (p - x >= 0)
    putchar(*--p);
  putchar('\n');

  return 0;
}

void
conv_base(int dec, int base, char *x)
{
  char           *p = x;
  int             w;
  w = dec % base;
  if (w <= 9)
    *p = '0' + w;
  else
    *p = 'a' + w - 10;
  if (dec /= base)
    conv_base(dec, base, p + 1);
}


Output:
1
dec base = /(�


Create a new paste based on this one


Comments: