The 5 versions are not equivalent: not all don't terminate when `stdin` is closed.

Instead of comparing the versions to one another other,
we can pick on the bad practices in each.

>     while (1)
>         while(scanf("%c", &d), d != '\n') {
>             printf("%d\n", d * d);
>         }

It's better to consistently add braces around the body of statements like `while` and `if`.
A common mistake is to write something like this:

    while (1)
        while(scanf("%c", &d), d != '\n') {
            printf("%d\n", d * d);
        }
        printf("...");

This may mislead a reader to think that the last `printf` is part of the outer loop, when it isn't. Just put the braces around the body always.

Another negative point in this version is having two statements inside the inner `while`. This is not easy to read. It's better to write in a way that there is no more than one statement per line. More generally, I recommend to avoid the `,` operator entirely.

The same point applies to this line in the 3rd version:

>     while((d = getchar()) != '\n') {

That is, there is an assignment within the conditional statement.
Avoid such "clever" writing style.
Stick to one statement per line.

And one more variation of the same issue, in the 4th version:

>     while ((d = getchar())) {