如何在C ++中打印多维数组

编程入门 行业动态 更新时间:2024-10-11 05:22:23
本文介绍了如何在C ++中打印多维数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

你好, 我们在C ++中接受了关于sudoko的练习。 任务:到确定整数集是否是有效的soduko解决方案。 此代码中预先定义了81个数字。到目前为止,我有这个。 问题:我如何传递一个多维数组。 我有点需要首先打印数独表格

hello, We were given an exercise about sudoko in C++. task: to determine if the set of integers is a valid soduko solution. the 81 numbers are pre-defined in this code. so far i have this. Problem: how do I pass a multi-dimensional array. I kinda need to print the sudoku table first

#include<iostream> using namespace std; int main(){ int row, column; row = column = 9; int array[row][column] = { { 4, 5, 2, 3, 9, 1, 8, 7, 6 }, { 3, 1, 8, 6, 7, 5, 2, 9, 4 }, { 6, 7, 9, 4, 2, 8, 3, 1, 5 }, { 8, 3, 1, 5, 6, 4, 7, 2, 9 }, { 2, 4, 5, 9, 8, 7, 1, 6, 3 }, { 9, 6, 7, 2, 1, 3, 5, 4, 8 }, { 7, 9, 6, 8, 5, 2, 4, 3, 1 }, { 1, 8, 3, 7, 4, 9, 6, 5, 2 }, { 5, 2, 4, 1, 3, 6, 9, 8, 7 } }; }

我使用给我们的示例指针代码,但这是一个单维数组。

Im using a sample pointer code given to us but this is a single-dimensional array.

#include<iostream> using namespace std; void printArray(int anArray[], int aSize); int main(){ int array[5] = {52,94,4,9,7}; printArray(array, 5); } void printArray(int anArray[], int aSize){ cout << aSize << endl; for(int *ptr=anArray; ptr-anArray < aSize; ptr++){ cout << *ptr << endl; } }

任何人都可以教我如何通过这个数组到函数?

can anyone teach me how do I pass this array to a function?

推荐答案

#include<iostream> #include<iomanip> using namespace std; const int iRow = 9; const int iColumn =9; void PrintArray(int iNum[][iColumn], int iR, int iC){ for(int i=0;i<iR;i++){ cout<< "\n"; for(int j=0; j<iC; j++){ cout<< "|"<<iNum[i][j]<<"|"; } } } int main(){ int iSud[iRow][iColumn] = { { 4, 5, 2, 3, 9, 1, 8, 7, 6 }, { 3, 1, 8, 6, 7, 5, 2, 9, 4 }, { 6, 7, 9, 4, 2, 8, 3, 1, 5 }, { 8, 3, 1, 5, 6, 4, 7, 2, 9 }, { 2, 4, 5, 9, 8, 7, 1, 6, 3 }, { 9, 6, 7, 2, 1, 3, 5, 4, 8 }, { 7, 9, 6, 8, 5, 2, 4, 3, 1 }, { 1, 8, 3, 7, 4, 9, 6, 5, 2 }, { 5, 2, 4, 1, 3, 6, 9, 8, 7 } }; PrintArray(iSud,iRow,iColumn); }

ok我终于找到了如何打印它的方法,但它需要更多设计才能让它看起来像数独表。有人可以帮助我如何制作上部和下部线条使数字看起来像在框内

ok I finally found a way on how to print it, but it needs some more designs to make it look like a sudoku table. can someone help how I can make the upper and lower portions lines to make the numbers look like inside the box

更多推荐

如何在C ++中打印多维数组

本文发布于:2023-11-30 15:53:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1650588.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多维   数组   如何在

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!