Form a number system with only 3 and 4. Find the nth number of the number system.

Eg.) The numbers are: 3, 4, 33, 34, 43, 44, 333, 334, 343, 344, 433, 434, 443, 444, 3333, 3334, 3343, 3344, 3433, 3434, 3443, 3444 ….

Eg.) The numbers are: 3, 4, 33, 34, 43, 44, 333, 334, 343, 344, 433, 434, 443, 444, 3333, 3334, 3343, 3344, 3433, 3434, 3443, 3444 ….

**My Solution::**#include<stdio.h> #include<conio.h> void bin(int n){ if(n>1) bin(n/2); printf("%d",(n%2)?3:4); } int main(){ int num,i; clrscr(); scanf("%d",&num); i = 1; do{ num -= 1<<i; i++; }while(num); --i; --i; num += 1<<i; bin(num); getch(); return 0; }

This comment has been removed by the author.

ReplyDelete