Hi guys , in my study book from which I re-learn C is task to generate all possible characters combination from numbers entered by the user. I know this algorithm must use combinatorics to calculate all permutations. Problem is how to implement algortihm.
// This program reads the four numbers from the user
// and saves them into the array. Once all numbers entered
// program will translate input numbers to letters
// like we have on phone keys, zero and and one will
// be translated into the space
// Author: solaris_user
// Date: 08.05.2011
#include <stdio.h>
#define ARRAY_SIZE 4
int main(void)
{
int phone_numbers[ARRAY_SIZE], counter, printer;
for (counter = 1; counter <= ARRAY_SIZE; counter++)
{
do {
printf("Enter %d phone number: ", counter);
scanf("%d", &phone_numbers[counter]);
if (phone_numbers[counter] < 0 || phone_numbers[counter] > 9)
{
printf("Incorrenct data input\n");
printf("Please try again\n");
}
} while (phone_numbers[counter] < 0 || phone_numbers[counter] > 9);
}
for (printer = 1; printer <= counter; printer++)
{
switch(phone_numbers[printer])
{
case 0: case 1:
{
printf("<space>\n");
break;
}
case 2:
{
printf("abc bac cab\n");
break;
}
case 3:
{
printf("cde dec ced\n");
break;
}
....
}
}
return 0;
}
Author says I must have four nested loops. So as a beginner I must ask for help from experienced programmers.
Thanks for reading and for your time