But a factorial can become quite large.
13! is already to large to fit into a 32bit variable.
21! doesn't even fit in 64 bit.
So you are limited to short strings.
But you can rise the limit.
Code:
#include <stdio.h>
#include <limits.h>
#include <stdlib.h>
long permut(short n, short k);
int main() {
int dl,i,n;
int *nl;
long p;
long m;
printf("\nEnter number of different letters (e.g. aaabb contains 2 different letters): ");
scanf("%d",&dl);
nl=malloc(sizeof(int)*dl);
n=0;
for(i=0; i<dl; i++) {
printf("\nEnter number of %d. letter: ",i+1);
scanf("%d",nl+i);
n+=nl[i];
}
p=1;
for(i=0; i<dl;i++) {
m=permut(n, nl[i]);
if( (LONG_MAX/m) < p) {
printf("Result is too big.");
exit(0);
}
p*=m;
n-=nl[i];
}
printf("\nPermutations: %ld",p);
}
long permut(short n, short k) {
long p=1;
int i,j;
if(n==k) return 1;
for(i=1, j=k+1; j<=n; j++, i++) {
if( (LONG_MAX/j) < p) {
printf("Result is too big.");
exit(0);
}
p*=j;
p/=i;
}
return p;
}
this code has no problems with the string:
"aabbbccddddefff" (15 letters)