当前位置:网站首页>YTU 2418: C语言习题 矩阵元素变换
YTU 2418: C语言习题 矩阵元素变换
2022-08-11 01:58:00 【51CTO】
2418: C语言习题 矩阵元素变换
时间限制: 1 Sec 内存限制: 128 MB
提交: 293
解决: 155
题目描述
将一个n×n(2<n<10,n为奇数)的矩阵中最大的元素放在中心,4个角分别放4个最小的元素(按从左到右、从上到下顺序依次从小到大存放),写一
函数实现。用main函数调用。
输入
输入n和矩阵中的每个元素
输出
变换后的矩阵
样例输入
样例输出
提示
主函数已给定如下,提交时不需要包含下述主函数
/* C代码 */
int main()
{
void change(int *,int );
int **a,*p,i,j;
int n;
scanf("%d",&n);
p=(int*)malloc(n*n*sizeof(int));
a=(int**)malloc(n*sizeof(int *));
for(i=0; i<n; i++)
a[i]=p+n*i;
for (i=0; i<n; i++) //输入矩阵
for (j=0; j<n; j++)
scanf("%d",&a[i][j]);
change(p,n); //调用函数,实现交换
for (i=0; i<n; i++) //输出已交换的矩阵
{
for (j=0; j<n; j++)
printf("%d ",a[i][j]);
printf("\n");
}
free(p);
free(a);
return 0;
}
/* C++代码 */
int main()
{
void change(int *,int );
int **a,*p,i,j;
int n;
cin>>n;
p=new int[n*n];
a=new int*[n];
for(i=0; i<n; i++)
a[i]=p+n*i;
for (i=0; i<n; i++) //输入矩阵
for (j=0; j<n; j++)
cin>>a[i][j];
change(p,n); //调用函数,实现交换
for (i=0; i<n; i++) //输出已交换的矩阵
{
for (j=0; j<n; j++)
cout<<a[i][j]<<" ";
cout<<endl;
}
delete []p;
delete []a;
return 0;
}
迷失在幽谷中的鸟儿,独自飞翔在这偌大的天地间,却不知自己该飞往何方……
边栏推荐
- OpenWrt之opkg详解
- 单面PCB布线阻抗的工程设计
- ARM development (4) How to read the chip manual for novice Xiaobai, bare metal driver development steps and pure assembly to achieve lighting, assembly combined with c lighting, c to achieve lighting
- 【HFSS学习记录1】实例:宽带非对称多节定向耦合器设计
- 两日总结十
- Shengxin experiment record (part2)--tf.reduce_sum() usage introduction
- 迭代器和生成器
- 如何实现FPGA的可重复性设计
- 本周四晚19:00知识赋能第六期第5课丨OpenHarmony WiFi子系统
- 进程间通信方式(2)有名管道
猜你喜欢
随机推荐
JVM类加载机制
21、阿里云oss
Sigma development pays attention to details
Ora - 00001 in violation of the only constraint
第二课第一周第4-6节 医学预后案例欣赏+作业解析
连流量染色都没有,你说要搞微服务?
How to realize the repeatable design of FPGA
Pytorch/TensorFlow/Numpy常用函数汇总
Matlab矩阵(数组)元素过滤常见方法详解
【HFSS学习记录1】实例:宽带非对称多节定向耦合器设计
Detailed explanation of common methods of filtering matrix (array) elements in Matlab
软件测试面试题:谈谈你对 cmm 和 is9000 的认识?
sql 使用到where和groupby时建立索引结果为啥是这样,原理是什么?
async和await的理解和用法
SyntaxError: invalid syntax
【websocket】
导入数据包上传宝贝提示“类目不能为空”是什么原因,怎么解决?
Lianshengde W801 series 5-WeChat applet and W801 Bluetooth communication routine (read notes)
Experiment record of Shengxin (part3)--scipy.spatial.distance_matrix
如何实现FPGA的可重复性设计









