用C语言实现的轴对称变换

 1 #include<stdio.h>
 2 
 3 main()
 4 {
 5   int i,p,n,k,f,c,h,g,w;
 6   int a[17][17];
 7 
 8   for(i=0;i<=8;i++)
 9     {
10       for(p=0;p<=8;p++)
11     {
12       a[i][p]=i+1;
13       for(n=0;n<=7;n++)
14         {
15           for(k=0;k<=7-n;k++)
16         {
17           a[n][k]=0;
18         }
19         }
20     }
21 
22     }
23   for(p=9;p<=16;p++)
24     {
25       for(f=0;f<=8;f++)
26     a[p][f]=a[16-p][f];
27     }
28   for(c=0;c<=16;c++)
29 
30     {
31  
32       for(h=9;h<=16;h++)
33     {
34       a[c][h]=a[c][16-h];
35      
36     }
37     }
38   for(g=0;g<=16;g++)
39     {
40       for(w=0;w<=16;w++)
41     {
42       printf("%d ",a[g][w]);
43     }
44       printf("
");
45  
46     }
47 }

运行结果如下:

当然此题也可以用C++实现,代码是

 1 #include<iostream>
 2 using namespace std;
 3 int main()
 4 {
 5  
 6  int a[17][17];
 7 for(int i=0;i<=8;i++)
 8 {
 9 for(int p=0;p<=8;p++)
10 {
11 a[i][p]=i+1;
12 for(int n=0;n<=7;n++)
13 {
14  for(int k=0;k<=7-n;k++)
15  {
16   a[n][k]=0;
17  }
18 }
19 }
20 
21 }
22 for(int p=9;p<=16;p++)
23 {
24   for(int f=0;f<=8;f++)
25      a[p][f]=a[16-p][f];
26 }
27 for(int c=0;c<=16;c++)
28 
29 {
30  
31     for(int h=9;h<=16;h++)
32     {
33      a[c][h]=a[c][16-h];
34      
35     }
36 }
37 for(int g=0;g<=16;g++)
38 {
39  for(int w=0;w<=16;w++)
40  {
41  cout<<a[g][w]<<" ";
42  }
43  cout<<endl;
44  
45 }
46 return 0;
47 }
原文地址:https://www.cnblogs.com/yeluqing/p/3827404.html