Question: /* Change this program so that if you give it two command-line arguments, it will convert the first argument from base 10 to the base

/*

Change this program so that if you give it two command-line arguments,

it will convert the first argument from base 10 to the base given in the

second argument. You can assume the base is between 2 and 36.

Example run:

./base.o 42 2

101010

./base.o 42 4

222

./base.o 99 5

344

*/

#include

#include

int main(int argc, char *argv[]) {

int four;

int num1 = atoi(argv[1]);

int num2 = atoi(argv[2]);

char a[100];

a[99] = '\0';

char *s = &a[99];

while (num1 > 0 && s > a) {

s--;

if (num1 % num2 == 0) *s = '0';

else *s = '1';

num1 /= 2;

}

printf("%s ", s);

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!