给定一个 n*n 的二维数组,任务是找到给定矩阵的反螺旋排列
Input : arr[4][4]={1,2,3,4, 5,6,7,8, 9,10,11,12 13,14,15,16}Output : 1 6 11 16 4 7 10 13

算法
STARTStep 1 -> declare start variables as r=4, c=4, i and jStep 2 -> initialize array as mat[r][c] with elementsStep 3 -> Loop For i=0 and i printStep 5 -> Loop For i=0 and i<r and i++ Print mat[i][4-1-i]EndSTOP
Example
的中文翻译为:
示例
#include#include using namespace std;int main() { int R=4,C=4,i,j; int mat[R][C] = { {1,2,3, 4}, {5,6,7,8},{9,10,11,12},{13,14,15,16}}; for(i=0;i<R;i++) { cout<<mat[i][i]<<" "; } cout<<""; for(i=0;i<R;i++) { cout<<mat[i][4-1-i]<<" "; }}
输出
如果我们运行上面的程序,它将生成以下输出
1 6 11 164 7 10 13
以上就是打印矩阵的对角线模式的详细内容,更多请关注创想鸟其它相关文章!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 chuangxiangniao@163.com 举报,一经查实,本站将立刻删除。
发布者:程序猿,转转请注明出处:https://www.chuangxiangniao.com/p/1444639.html
微信扫一扫
支付宝扫一扫