月亮偷着哭... 2022-03-01 14:41 采纳率: 84.6%
浏览 656
已结题

[Error] 'a' was not declared in this scope如何解决

#include<stdio.h>
#include<string.h>
#include<math.h>
int x,y,temp,a[n][n];
int n; 
int main()
{
    int transpose(int a[][]);    
    printf("input:\n");
    scanf("%d",&n);
    for(x=0;x<n;x++)
        {
        for(y=0;y<n;y++)
         {
            scanf("%d",&a[x][y]);
         }
        }
    transpose(a);
    for(x=0;x<n;x++)
        {
        for(y=0;y<n;y++)
        printf("%d ",a[x][y]);
        printf("\n");
         }
    
}
int transpose(int a[][])
{
    for(x=0;x<n;x++)
        for(y=x;y<n;y++)
            {
            temp=a[y][x];
            a[y][x]=a[x][y];
            a[x][y]=temp;
              }

}

出现了狠多错误 但是我不知道该怎么修改 是二维数组定义出错吗

img

  • 写回答

2条回答 默认 最新

  • qzjhjxj 2022-03-01 14:51
    关注

    数组的大小需要常数,修改如下,供参考:

    #include<stdio.h>
    #include<string.h>
    #include<math.h>
    #define N 20
    int main()
    {
        int x, y, temp, a[N][N];
        int n;
        int transpose(int a[][N], int n);
        printf("input:\n");
        scanf("%d", &n);
        for (x = 0; x < n; x++)
        {
            for (y = 0; y < n; y++)
            {
                scanf("%d", &a[x][y]);
            }
        }
        transpose(a, n);
        for (x = 0; x < n; x++)
        {
            for (y = 0; y < n; y++)
                printf("%d ", a[x][y]);
            printf("\n");
        }
    }
    int transpose(int a[][N],int n)
    {
        int x, y, temp;
        for (x = 0; x < n; x++)
            for (y = x; y < n; y++)
            {
                temp = a[y][x];
                a[y][x] = a[x][y];
                a[x][y] = temp;
            }
        return 0;
    }
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 3月9日
  • 已采纳回答 3月1日
  • 创建了问题 3月1日

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改