This was a month ago. ( I have improved since then ( ashamed of this code ) )
Its not exactly the same problem but the method should be the same. My solution was a little messy.
Theres should be a better solution than mine. As this was made by a beginner .
This code counts and prints all the possible combination of the last the four digits in a telephone number.
Code:
#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<stdlib.h>
#include<conio.h>
#define A 65
int main()
{
char *icomb;
int intcomb[4] = { 0 };
char input[20] = { 0 };
int ctr1, ctr2, ctr3, ctr4;
int permutation = 0;
clrscr();
printf( "phone: " );
fgets( input, sizeof( input ), stdin );
icomb = strchr( input, '\n' );
icomb = NULL;
icomb = strchr( input, '-');
icomb = &icomb[1];
printf( "last 4 digit is %s", icomb );
for( ctr1 = 0; ctr1 < 3; ctr1++ ){
for( ctr2 = 0; ctr2 < 3; ctr2++ ){
for( ctr3 = 0; ctr3 < 3; ctr3++ ){
for( ctr4 = 0; ctr4 < 3; ctr4++ ){
printf( "\n%c%c%c%c",
((icomb[0]-48)<2?'0':(((icomb[0]-48)-2)*3)+A+ctr1+0),
((icomb[1]-48)<2?'0':(((icomb[1]-48)-2)*3)+A+ctr2+0),
((icomb[2]-48)<2?'0':(((icomb[2]-48)-2)*3)+A+ctr3+0),
((icomb[3]-48)<2?'0':(((icomb[3]-48)-2)*3)+A+ctr4+0));
permutation++;
if( icomb[3]-48 < 2 ) break;
}
if( icomb[2]-48 < 2 ) break;
}
if( icomb[1]-48 < 2 ) break;
}
if( icomb[0]-48 < 2 ) break;
}
printf( "\n\nTotal Permutation is %d", permutation );
getch();
return 0;
}