Check if two strings are anagrams - HackerEarth
How do I make this code as small (shorter code) as possible?


You could change this:


if(strcmp(str1,str2)==0)
    printf("YES\n");
else
    printf("NO\n");



Like this, using the ternary operator and puts:

puts(strcmp(str1, str2) ? "NO" : "YES");


Technically,
you could also get rid of much of the whitespace and concatenate all instructions on a single line with semicolons.
But that's probably not what you really want.

If your aim is simplicity, then I think this is about as simple and short as it gets.

For readability, it would be better to add spaces around operators, for example like this:

    if (str[j] &gt; str[j+1])
    {
        swap = str[j];
        str[j] = str[j+1];
        str[j+1] = swap;
    }


Some minor final remarks:


bubble sort is a slow sorting algorithm, but with words of max 100 letters, it's probably good enough
uppercase and lowercase letters will be treated differently, but since the treatment of letter case is unspecified, that might be fine too