I get homework, but I put it in it. Maybe you can help me. The task is below.
Read the integer number of the keyboard in the decimal system and create a new number system.
Print the console number recorded in the new notation.
I did only for 2-10 systems, and I canβt do 10 to 36. I tried to do something like this in the second loop:
if ( result > 9 ) { printf("%c", 55+number); } else { printf("%d", result); }
my code is:
#include <stdio.h> int main() { int number, base; int i, result; scanf("%d %d", &number, &base); if ( number < base ) { printf("%d\n", number); } else { for ( i = base; i <= number / base; i *= base ); for ( int j = i; j >= base; j /= base ) { result = number / j; printf("%d", result); number = number % j; } printf("%d\n", number%base); } return 0; }
c
Eric Posolsky
source share