C语言输入不确定数量的数字

#include <stdio.h>


int main() {
	char ch; 
	int n, k = 0;
	int arr[100] = { 0 };
	while((ch = getchar()) && ch != '\n') {
		ungetc(ch, stdin);
		scanf("%d", &n);
		arr[k++] = n;
	}
	
	for (int i = 0; i < k; i++) {
		printf("%d ", arr[i]);
	}

	return 0;
	
}
posted @ 2020-09-02 18:57  不夜君  阅读(2482)  评论(0编辑  收藏  举报