Scanf has a serious problem if you don't use it correctly. For example:
int x,y;
scanf("%d%d",&x,&y);
If we input a charter instead of a number, system will continue using the last effective input (input buffer) as input and never give you the chance to input. In order to get rid of this deadlock, we should use setbuf() or rewind() to clear the input buffer.
In the context of the code, we should input two integers with space in the middle of them. Or we should input one integer and enter 'enter', then input another integer. We should not use comma or other symbols between two integers. If we use a comma in the middle, system will only read the first integer for x. Then the integer after comma will combine with the next first input integer.
Rand() problem is that if we use the same seed each time, the sequence of generated numbers will be the same.