Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <stdbool.h>
- #include <string.h>
- #define MAX 15
- bool Transfer(int, char *, int);
- int main(int argc, char **argv) {
- char string[MAX];
- memset(string, '\0', sizeof(char) * MAX);
- Transfer(atoi(argv[1]), string, atoi(argv[2]));
- int counter = strlen(string);
- char swapstring[counter];
- for (int i = 0, j = counter - 1; i < counter; j--, i++) {
- swapstring[i] = string[j];
- }
- printf("%s", swapstring);
- }
- bool Transfer(int number, char *string, int sys) {
- int rest;
- int counter = 0;
- while(1) {
- if ((rest = number % sys) >= 10) {
- string[counter] = rest + 55;
- } else {
- string[counter] = rest + 48;
- }
- if ((number = number / sys) == 0) {
- return true;
- }
- if ((number != 0 && counter >= MAX - 1)) {
- return false;
- }
- counter++;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement