Here is the program for the above (tested).
#include <stdio.h>
int main()
{
int num = 0, choice = 0, ret;
char no[32];
char frmt[] = {"dox"};
printf("Entery your choice < 1:desimal > < 2:octal > < 3:hexadecimal > : ");
scanf("%d", &choice);
printf("\nEnter your number : ");
/*
After getting the input from user just storing the input number into char array as a string.
*/
switch (choice) {
case 1:
scanf("%d", &num);
sprintf(no, "%0d", num);
break;
case 2:
scanf("%o", &num);
sprintf(no, "%0o", num);
break;
case 3:
scanf("%x", &num);
sprintf(no, "%0x", num);
break;
default:
printf("Invalid choice...\n");
}
/*
The below print will print the input number in respective format i.e decimal/ octal/ hexadecimal.
and the number of digit for that number.
*/
printf(" : contains %d digits.\n", printf("%s", no));
return 0;
}
If you have any question you can ask me :)