指针操作二维数组
来源:互联网 发布:淘宝酒类授权怎么写 编辑:程序博客网 时间:2024/05/27 09:47
题目描述:
从键盘输入一个3X3的整数矩阵,输出该矩阵并求出主对角线元素的和。
源代码:
从键盘输入一个3X3的整数矩阵,输出该矩阵并求出主对角线元素的和。
源代码:
<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->// test3.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "iostream"
using namespace std;
int main(int argc, char* argv[])
{
int a[3][3],i,j,s=0;
int (* ptr)[3];
ptr=a;
cout<<"请输入矩阵的值:";
for(i=0;i<3;i++)
for(j=0;j<3;j++)
{
cin>>*(*(ptr+i)+j);
if(i==j)
s+=*(*(ptr+i)+j);
}
cout<<"输出矩阵:\n";
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
cout<<ptr[i][j]<<" ";
cout<<endl;
}
cout<<"矩阵主对角线元素的和为:"<<s<<endl;
return 0;
}
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->// test3.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "iostream"
using namespace std;
int main(int argc, char* argv[])
{
int a[3][3],i,j,s=0;
int (* ptr)[3];
ptr=a;
cout<<"请输入矩阵的值:";
for(i=0;i<3;i++)
for(j=0;j<3;j++)
{
cin>>*(*(ptr+i)+j);
if(i==j)
s+=*(*(ptr+i)+j);
}
cout<<"输出矩阵:\n";
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
cout<<ptr[i][j]<<" ";
cout<<endl;
}
cout<<"矩阵主对角线元素的和为:"<<s<<endl;
return 0;
}
- 指针操作二维数组
- 用指针操作二维数组
- 数组指针操作一维二维数组
- 使用指针操作二维数组;输出二维数组
- 用指针操作二维数组 C 语言
- 怎么用指针操作二维数组
- C语言:使用指针操作二维数组
- 二维数组 数组指针
- 二维数组 指针数组
- 二维指针与二维数组
- 二维数组与二维指针
- 二维数组和二维指针
- 二维数组和二维指针
- 二维数组和二维指针
- 二维指针和二维数组
- 二维数组和二维指针
- 二维指针和二维数组
- 二维数组与二维指针
- (zs)数学类题目小结
- 用户研究:10种类型的IT人士性格分析
- strlen函数的实现
- 动态创建整形数组
- 【转】是该重新定义“人”的时候了
- 指针操作二维数组
- gdb break 断点设置(一)
- sizeof操作符
- JS 的replace
- 银行卡术语
- 添加自己编写的模块到ns-3中出现undefined reference to问题的解决
- redhat linux根目录
- 输出n个不同字符的所有排列方式(据说是京东笔试题)
- 谷歌拼音与魔兽世界