Permutation of words in a sentence There is a problem which discusses in how many ways can the words in a sentence be permuted . I wrote a code as follows which works for the sentences (I think so) . It would be helpful if anyone can assure me if it's actually correct or not . Besides , any suggestion regarding the shortening of code or easing the logic is appreciated . Thanks...

#include &lt;stdio.h&gt;
#include &lt;string.h&gt;

int factorial(int x)
{
    if(x&lt;=0) return 1;
    else return x*factorial(x-1);
};

int main(void)
{
    int T;//number of test cases
    scanf("%d",&amp;T);
    while(T--){
    char str[20];
    scanf(" %[^\n]",str);
    int i,j,k,m,count=0,l,p=1,n;
    l=strlen(str);
    for(i=0;i&lt;l;i++){
        if(str[i]==' '){
            count++;
        }
    }
    m=count+1;
    char arr[m][50];
    int check[m],func[m];
    for(i=0,k=0,j=0;j&lt;=l;j++){
        if(str[j]==' '||j==l){
            check[i]=0;func[i]=1;
            arr[i][k]='\0';
            i++;
            k=0;
        }
        else{
            arr[i][k]=str[j];
            k++;
        }
    }
    for(i=0;i&lt;m;i++){
  for(j=i+1;j&lt;m;j++){
    if(check[i]==0&amp;&amp;strcmp(arr[i],arr[j])==0){
        check[j]++;
        func[i]++;
    }
  }
}
for(i=0;i&lt;m;i++){
    p*=factorial(func[i]);
}
n=factorial(m)/p;
printf("%d/%d\n",1,n);
   }
 return 0;
}


Input:

       2

       I eat rice

       no game no life 


Output:

       1/6

       1/12


N.B.: The permutation within a word is to be ignored .
Some comments on the style of your code. 


Formatting. Your code is hard to read because there are no spaces.
Also the formatting seems to be off. It might be easier to read like this:

int main(void)
{
    int T;//number of test cases
    scanf("%d", &amp;T);
    while (T--) {

        char str[20];
        scanf(" %[^\n]", str);

        int i, j, k, m, count = 0, l, p = 1, n;
        l = strlen(str);

        for (i = 0; i &lt; l; i++) {
            if (str[i] == ' ') {
                count++;
            }
        }

        m = count + 1;
        char arr[m][50];
        int check[m], func[m];

        for (i = 0, k = 0, j = 0; j &lt;= l; j++) {
            if (str[j] == ' ' || j == l) {
                check[i] = 0; func[i] = 1;
                arr[i][k] = '\0';
                i++;
                k = 0;
            }
            else {
                arr[i][k] = str[j];
                k++;
            }
        }

        for (i = 0; i &lt; m; i++) {
            for (j = i + 1; j &lt; m; j++) {
                if (check[i] == 0 &amp;&amp; strcmp(arr[i], arr[j]) == 0) {
                    check[j]++;
                    func[i]++;
                }
            }
        }

        for (i = 0; i &lt; m; i++) {
            p *= factorial(func[i]);
        }

        n = factorial(m) / p;
        printf("%d/%d\n", 1, n);
    }
    return 0;
}

Don't use comments for what could be described in the code directly. This:

    int T;//number of test cases
    scanf("%d", &amp;T);
    while (T--) {


Should be really this:

    int number_of_test_cases;
    scanf("%d", &amp;number_of_test_cases);
    while (number_of_test_cases--) {

Avoid long functions for maintainability and readability. You wrote one function for the factorial calculation; good. But now take a look
    at the main() function. Can you guess what the steps are in the while
    by looking at it? There's too much stuff going on in the main().
    Isolate parts which do one thing into a function. For example this
    piece:

    int i, j, k, m, count = 0, l, p = 1, n;         
    l = strlen(str);

    for (i = 0; i &lt; l; i++) {           
        if (str[i] == ' ') {
            count++;            
        }       
    }


First of all I would write the variables on several lines to have it more readable:

    int i;
    int j;
    int k;
    int m;
    int count = 0;
    int l; 
    int p = 1;
    int n;
    l = strlen(str);

    for (i = 0; i &lt; l; i++) {
        if (str[i] == ' ') {
            count++;
        }
    }


Then we realize that j, k, m, p and n are not even needed yet at this point, so we put 
 them after all this:

    int i;
    int count = 0;
    int l; 
    l = strlen(str);

    for (i = 0; i &lt; l; i++) {
        if (str[i] == ' ') {
            count++;
        }
    }

    int p = 1;
    int j;
    int k;
    int m;
    int n;


Then another thing is l can be directly initialized with strlen(str). Also I renamed 
it everywhere in the program to length which  states more easily for a reader what it 
does.

This gives us this:

    int i;
    int count = 0;
    int length = strlen(str);

    for (i = 0; i &lt; length; i++) {
        if (str[i] == ' ') {
            count++;
        }
    }


Now we should make it a function so it looks like this:

    int length = strlen(str);
    int count = get_count_of_whitespace(&amp;str, length);


Proceed with the rest of the main function like that by refactoring it into 
manageable chunks, and probably with that alone you will find some mistakes or improvements 
for your algorithm.