#include <stdio.h> int main() { int ch; while (scanf("%d", &ch) == 1 && ch >= 0) ; return 0; }
当输入值不是自然数时,程序就能正常退出。