If you're worried about performance due to recalculating these numbers a lot, see if you're recalculating the same numbers over and over, in which case you can memoize or otherwise tabulate the results.
linnie
2016-06-01 02:32:47 UTC
If the string length is not known in advance, the only way to do this is through a recursive function. Since you can't use functions, you can write a program to write all combinations of a 1, 2, 3, 4 and 5 character long strings. It will be something like this: char str[5]; scanf( "%d", str ); switch( len(string) ) : case 1: printf( "%d", str ); break; case 2: // str is 2 characters long int i, j; for( i = 0; i < 2; i++ ) printf( "%d", str[i] ); for( j = 0; j < 2; j++ ) if( j != i ) { printf( %d \n", str[ j ] ); } case 3: // str is 3 characters long int i, j, k; and so on...
?
2010-09-09 07:25:47 UTC
You may need to write your own factorial function (it isn't hard), or just copy paste what I wrote below