我希望函数或循环遍历数组并打印出每个元素,直到它已打印10个元素。在这种情况下,将开始新的一行并继续打印。例如。 1 2 3 4 5 6 7 8 9 10
这是一个程序,该程序可以像50年代的家庭主妇那样处理数组,并对该数组进行许多计算和更改。
这是我当前对问题背后逻辑的攻击。
int main()
{
test = new int[100];
for (int i = 0; i < 100; i++){
//Set array to rand
test[i] = rand() % 44 + 55;
}
printf("original List\n");
for (int i = 0; i < 100; i++){
// print original order
printf("%d\n",test[i]);
}
sortArr;
// function call sort array ascend
printf("\Sorted List\n");
for (int i = 0;i < 100;i++) {
// print sorted order
printf("%d,",test[i]);
int temp;
//temp counter for width of printout
for (temp = 0;temp < 10;temp++) cout<< "\n" << endl;
sum += test[i];
}
期望是一个输出块,该输出块由网格中的100个数组元素组成,每行宽度为10个元素。
实际结果是一堆新的线路循环,让我更加头疼。