- #1
4102
- 7
- 0
Hi I'm making a program that generates a different arrangement of letters in C.
For example, the word ALTEC will be rearranged randomly by the program.
the output would be "LETAC" or "CEALT" etc.
The program should use all the given letters and not repeat the letters.
Here's a code sample I made but the problem is that it repeats other letters, example output of this is like "ELTAA" instead of "ELTAC", it should not repeat the letter that is used already. Also I need only ONE output, and not all the possible permutations.
by the way, the some of the codes used is C++, what i need is for C. It's quite a mix up already I'm quite confused.
Please help! Thanks!
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
srand(time(NULL));
char possibilities[6] = "ALTEC";
for(int i = 0; i < 5; i++)
{
cout << possibilities[rand() % 5];
}
cin.get();
return 0;
}
For example, the word ALTEC will be rearranged randomly by the program.
the output would be "LETAC" or "CEALT" etc.
The program should use all the given letters and not repeat the letters.
Here's a code sample I made but the problem is that it repeats other letters, example output of this is like "ELTAA" instead of "ELTAC", it should not repeat the letter that is used already. Also I need only ONE output, and not all the possible permutations.
by the way, the some of the codes used is C++, what i need is for C. It's quite a mix up already I'm quite confused.
Please help! Thanks!
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
srand(time(NULL));
char possibilities[6] = "ALTEC";
for(int i = 0; i < 5; i++)
{
cout << possibilities[rand() % 5];
}
cin.get();
return 0;
}