鱼七啊 发表于 2020-12-22 15:07:34

数组列与列换位请求帮改。

#include<stdio.h>
void func(int a)
{
for(int n=0;n<3;n++)
                {for(int m=0;m<4;m++)
            {
                        int temp;
                        temp=a;
                        a=a;
                        a=temp;}
                }
int main()
{
    int a={{1,2,3,4,5,6},
                        {2,3,4,5,6,7},
                        {3,4,5,6,7,8},
                        {4,5,6,7,8,9},
                        {5,6,7,8,9,10}};
int x,y;
{for(x=0;x<5;x++)
   for(y=0;y<6;y++)
printf("%d",a);
}
func(a);
{for(x=0;x<5;x++)
    for(y=0;y<6;y++)
printf("%d",a);
}
return(0);
}

xieglt 发表于 2020-12-22 15:18:08

#include<stdio.h>
void func(int a)
{
        for(int n=0;n<3;n++)
        {for(int m=0;m<4;m++)
        {
                int temp;
                temp=a;
                a=a;
                a=temp;
        }
        }
}

int main()
{
                int a=
                {
                        {1,2,3,4,5,6},
                        {2,3,4,5,6,7},
                        {3,4,5,6,7,8},
                        {4,5,6,7,8,9},
                        {5,6,7,8,9,10}
                };

                int x,y;

                for(x=0;x<5;x++)
                {        for(y=0;y<6;y++)
                                printf("%d,",a);
                        printf("\n");
                }
                func(a);
                for(x=0;x<5;x++)
                {        for(y=0;y<6;y++)
                                printf("%d,",a);
                        printf("\n");
                }
                return(0);
}

风过无痕1989 发表于 2020-12-22 15:27:48

没有明白你的题目意思,你怎么列与列互换?
先指出程序一个错误,自定义函数缺少一个花括号

鱼七啊 发表于 2020-12-22 15:28:20

怎么加个换行就好了呢

风过无痕1989 发表于 2020-12-22 15:42:55

鱼七啊 发表于 2020-12-22 15:28
怎么加个换行就好了呢

是第1列换到第6列,第2列换到第5列,第3列换到第4列,也就是说水平番吗?

风过无痕1989 发表于 2020-12-22 15:49:44

鱼七啊 发表于 2020-12-22 15:28
怎么加个换行就好了呢

你程序的错误,已经全部修正,见注释
#include<stdio.h>
void func(int a)
{
    for (int m = 0;m < 5;m++)   // 错误有2:1、换列应保持行不动,行应该在外循环;2、行有5行,而不是4行
        {
          for (int n = 0;n < 3;n++)
                {
                        int temp;
                        temp = a;
                        a = a;
                        a = temp;
                }
        }
}    // 缺少花括号
int main()
{
                int a = { { 1,2,3,4,5,6 },
                { 2,3,4,5,6,7 },
                { 3,4,5,6,7,8 },
                { 4,5,6,7,8,9 },
                { 5,6,7,8,9,10 } };

                int x, y;
                for (x = 0;x<5;x++)
                {                     // 花括号位置错误
                        for (y = 0;y < 6;y++)
                        {
                                printf("%3d", a);
                        }
                        printf("\n");
                }
                printf("\n");
               
                func(a);
               
                for (x = 0;x<5;x++)
                {                      // 花括号位置错误
                        for (y = 0;y < 6;y++)
                        {
                                printf("%3d", a);
                        }
                        printf("\n");
                }
                return(0);
}

鱼七啊 发表于 2020-12-22 22:08:08

风过无痕1989 发表于 2020-12-22 15:42
是第1列换到第6列,第2列换到第5列,第3列换到第4列,也就是说水平番吗?

非常感谢非常感谢

风过无痕1989 发表于 2020-12-22 22:58:43

鱼七啊 发表于 2020-12-22 22:08
非常感谢非常感谢

不必客气!
页: [1]
查看完整版本: 数组列与列换位请求帮改。