The problem is easily solved in Python: the out-of-the-box question type python3_w_input replaces the standard Python input function with one that does as you suggest, echoing standard input to standard output as it is consumed.
With other languages, though, it's harder. We never bothered to develop an equivalent question type in other languages as we teach Python as our first language and after that we expect students to understand files and I/O redirection.
But certainly it can be done. I just wrote a getchar.c that can be compiled and linked in to replace the library getchar function. Adding that getchar.c to a question as a support file and customising the question to compile that file as well, gives a question that behaves like the following:

The support file getchar.c is the following:
/* A getchar function to replace the standard one, which echoes
* characters from stdin to stdout as they are consumed.
*/
struct _IO_FILE;
typedef struct _IO_FILE FILE;
extern int fgetc(FILE *__stream);
extern FILE *stdin;
extern int putchar(int __c);
int getchar() {
int c = fgetc(stdin);
putchar(c);
return c;
}
The xml export of the question is attached. Note that it's customised, and you have to open the Advanced Customisation section to see how the compileargs parameter is set to compile the added file.
You should be able to do the same sort of thing with scanf, though it will be much harder. You'd probably want to start with the source code for scanf (see here and here) and tweak to do the output as well.
You could of course turn this into a question type. If you do so, could you post it back here, please?