Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5b0061c

Browse files
authored
Update 数组旋转问题.c
1 parentebf36ea commit5b0061c

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

‎经典项目/数组旋转问题.c‎

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,38 @@
1-
#
1+
//下面程序的功能是将一个 4×4 的数组进行逆时针旋转 90 度后输出,要求原始数组的数据随机输入,新数组以 4 行 4 列的方式输出。
2+
3+
//主要涉及知识点:二维数组的输入及输出、循环嵌套与二维数组的结合、输出的格式控制。
4+
5+
6+
#include<stdio.h>
7+
intmain(){
8+
inta[4][4],b[4][4],i,j;/*a 存放原始数组数据,b 存放旋转后数组数据*/
9+
printf("input 16 numbers: ");
10+
/*输入一组数据存放到数组 a 中,然后旋转存放到 b 数组中*/
11+
for(i=0;i<4;i++){
12+
for(j=0;j<4;j++){
13+
scanf("%d",&a[i][j]);
14+
printf("%6d",a[i][j]);
15+
b[3-j][i]=a[i][j];
16+
}
17+
printf("\n");
18+
}
19+
printf("array b:\n");
20+
for(i=0;i<4;i++){
21+
for(j=0;j<4;j++)
22+
printf("%6d",b[i][j]);
23+
printf("\n");
24+
}
25+
return0;
26+
}
27+
28+
//运行结果:
29+
//input 16 numbers: 1 34 6 4 56 2 5 6 9 12 23 23 46 77 12 34
30+
// 1 34 6 4
31+
// 56 2 5 6
32+
// 9 12 23 23
33+
// 46 77 12 34
34+
//array b:
35+
// 4 6 23 34
36+
// 6 5 23 12
37+
// 34 2 12 77
38+
// 1 56 9 46

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp