Có lẽ cậu chưa biết, nhưng hàm scanf thực ra có giá trị trả về đấy 
From manual:
int
scanf(const char *restrict format, ...);
và đây là ý nghĩa của giá trị trả về, cũng trong manual:
RETURN VALUES
These functions return the number of input items assigned. This can be fewer than provided for, or even zero, in the event of a matching failure. Zero indicates that, although there was input available, no conversions were assigned; typically this is due to an invalid input character, such as an alphabetic character for a `%d’ conversion. The value EOF is returned if an input failure occurs before any conversion such as an end-of-file occurs. If an error or end-of-file occurs after conversion has begun, the number of conversions which were successfully completed is returned.
Cậu có thể tham khảo implement dưới đây của tớ về cách dùng giá trị trả về của scanf để xác định đầu vào có là số nguyên không. Vì format của tớ là “%d”, vậy nên:
- Nếu scanf trả về 1, tức là gán thành công 1 biến int
- Nếu scanf trả về 0, tức là không gán thành công biến int nào => người dùng đã nhập sai kiểu.
Nhớ là nếu dùng scanf, cậu luôn phải cân nhắc clear buffer.
int getIntBetween(int lower, int upper) {
int res;
do {
res = getInt();
if(res < lower || res > upper) {
printf("Invalid integer. Please enter another integer in range [%d, %d] again!\n", lower, upper);
}
} while(res < lower || res > upper);
return res;
}
int getInt() {
int result;
while(scanf("%d",&result) != 1) {
printf("This is not an integer number. Please retype the input: ");
while(getchar() != '\n');
}
while(getchar() != '\n');
return result;
}