要实现多组数据的输入,可以使用循环结构来重复读取数据。以下是一个示例代码:
#include <stdio.h>
int main() {
int numSets, numElements;
printf("Enter the number of data sets: ");
scanf("%d", &numSets);
for (int i = 0; i < numSets; i++) {
printf("Enter the number of elements in data set %d: ", i+1);
scanf("%d", &numElements);
printf("Enter %d elements:\n", numElements);
for (int j = 0; j < numElements; j++) {
int element;
scanf("%d", &element);
// 处理输入的数据
}
}
return 0;
}
在上面的示例中,首先输入要处理的数据集的数量numSets
,然后在循环中输入每个数据集的元素数量和具体的元素数据。在实际应用中,可以根据具体的需求修改循环结构和数据处理逻辑。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:scanf在C语言中如何实现格式化输入