I'm writing a code which tells the user how many times a word they input can be written as. I know that the general "equation" one could call it is:
Let's say x = number of letters in the word, y = number of repeating letters;
x! - y! = answer
I managed to get the factorial part working, but I cannot seem to figure out how to see if a word has repeating letters, hopefully you guys can help!
#include <iostream>
#include <string.h>
usingnamespace std;
int factorial(int n); //prototyping the factorial function
int main()
{
while (1) {
char word[5000]; //I just entered a random value here
int wordLength;
cout << "Enter a word: ";
cin >> word;
wordLength = strlen(word);
cout << "The word " << "'" << word << "'" << " can be rearranged " << factorial(wordLength) << " times uniquely" << endl;
return 0;
}
}
int factorial(int n){ //factorial function
if (n== 1){
return 1;
} else {
return n*factorial(n-1);
}}