当前位置:网站首页>Output a spiral matrix C language
Output a spiral matrix C language
2022-07-07 08:52:00 【Please Sit Down】
Clockwise :
int main(){
int a[10][10],i,j,k=0,m,n;
printf("Enter n(n<10):");
scanf("%d",&n);
if(n%2==0) m=m/2;
else m=m/2+1;
for(i=0;i<m;i++){
for(j=i;j<n-i;j++){
k++; a[i][j]=k;
}
for(j=i+1;j<n-i;j++){
k++; a[j][n-i-1]=k;
}
for(j=n-i-2;j>=i;j--){
k++; a[n-i-1][j]=k;
}
for(j=n-i-2;j>=i+1;j--){
k++; a[j][i]=k;
}
}
for(i=0;i<n;i++){
for(j=0;j<n;j++){
printf("%5d",a[i][j]);
}
printf("\n");
}
return 0;
}

Anti-clockwise :
int main(){
int a[10][10],i,j,k=0,m,n;
printf("Enter n(n<10):");
scanf("%d",&n);
if(n%2==0) m=m/2;
else m=m/2+1;
for(i=0;i<m;i++){
for(j=i;j<n-i;j++){
k++; a[j][i]=k;
}
for(j=i+1;j<n-i;j++){
k++; a[n-i-1][j]=k;
}
for(j=n-i-2;j>=i;j--){
k++; a[j][n-i-1]=k;
}
for(j=n-i-2;j>=i+1;j--){
k++; a[i][j]=k;
}
}
for(i=0;i<n;i++){
for(j=0;j<n;j++){
printf("%5d",a[i][j]);
}
printf("\n");
}
return 0;
} 
边栏推荐
- JS的操作
- Gson converts the entity class to JSON times declare multiple JSON fields named
- 实现自定义内存分配器
- IP地址的类别
- 数据库存储---表分区
- Count sort (diagram)
- Tronapi-波场接口-源码无加密-可二开--附接口文档-基于ThinkPHP5封装-作者详细指导-2022年7月6日-新手快速上手-可无缝升级tp6版本
- MySQL主从延迟的解决方案
- Markdown editor Use of MD plug-in
- Speaking of a software entrepreneurship project, is there anyone willing to invest?
猜你喜欢

idea里使用module项目的一个bug

Why choose cloud native database

oracle一次性说清楚,多种分隔符的一个字段拆分多行,再多行多列多种分隔符拆多行,最终处理超亿亿。。亿级别数据量
![[MySQL] detailed explanation of trigger content of database advanced](/img/6c/8aad649e4ba1160db3aea857ecf4a1.png)
[MySQL] detailed explanation of trigger content of database advanced

关于基于kangle和EP面板使用CDN

Download and install orcale database11.2.0.4

Greenplum 6.x monitoring software setup

JS的操作

leetcode134. gas station

路由信息协议——RIP
随机推荐
ESP32-ULP协处理器低功耗模式RTC GPIO中断唤醒
QT charts use (rewrite qchartview to realize some custom functions)
Analysis of using jsonp cross domain vulnerability and XSS vulnerability in honeypot
Frequently Asked Coding Problems
Mountaineering team (DFS)
Why choose cloud native database
[Chongqing Guangdong education] accounting reference materials of Nanjing University of Information Engineering
为不同类型设备构建应用的三大更新 | 2022 I/O 重点回顾
let const
最长上升子序列模型 AcWing 1017. 怪盗基德的滑翔翼
uniapp 微信小程序监测网络
Greenplum 6.x build_ install
如何统计项目代码行数
Sign and authenticate API interface or H5 interface
RuntimeError: Calculated padded input size per channel: (1 x 1). Kernel size: (5 x 5). Kernel size c
let const
Selenium automation integration, eight years of testing experience, soft test engineer, an article to teach you
selenium自动化集成,八年测试经验软测工程师,一篇文章带你学懂
如何在快应用中实现滑动操作组件
[MySQL] detailed explanation of trigger content of database advanced