如何解决DECLARATION SYNTAX ERROR? [英] how to fix DECLARATION SYNTAX ERROR?

查看:991
本文介绍了如何解决DECLARATION SYNTAX ERROR?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  #include   <   stdio.h  >  
#include < conio.h >

int main()
{
int i,j,a [ 3 ] [ 3 ];
for (i = 0 ; i< 3; i ++)
{
for (j = 0 ; j< 3; j ++)
{
scanf( %d,& a [i] [j]);
}
}
// 没有转置的数组
// 显示
(i = 0 ; i< 3; i ++)
{
for (j = 0 ; j <3; j ++)
{
printf( %d,a [i]);
}
printf( / n);
}
// 转置后的数组
for (j = 0 ; j< 3; j ++))
{
printf( %d,& a [j]);
}
getch();
}

解决方案

函数定义不是单个语句 - 它始终以大括号对开始和结束。

然后你在转换后的数组for循环中有一个虚假的)。

尝试:

  #include   <   stdio.h  >  
#include < conio.h >
int main()
{
int i,j,a [ 3 ] [ 3 ];
for (i = 0 ; i< 3; i ++)
{
for (j = 0 ; j< 3; j ++)
{
scanf( %d,& a [i] [j]);
}
}
// 没有转置的数组
// 显示
(i = 0 ; i< 3; i ++)
{
for (j = 0 ; j <3; j ++)
{
printf( %d,a [i]);
}
printf( / n);
}
// 转置后的数组
for (j = 0 ; j< 3; j ++)
{
printf( %d,& a [j]);
}
getch();
}





但请帮个忙:一个字符变量名称很容易输入,但它们不会告诉你它们用于什么。对于这样一个简单的例子,这不是一个主要的问题,但如果你的课程开始建立在这个基础上,如果你使用描述数据而不是a的专有名称,它会变得非常有用。 / blockquote>

Quote:

for(i = 0; i< 3; i ++)

{

for(j = 0; j< 3; j ++)

{

printf(%d,a [i ]);

}

printf(/ n);

}

//转置后的数组

for(j = 0; j <3; j ++))

{

printf(%d,& a [j ]);

}



应该是:

  for (i =  0 ; i< 3; i ++)
{
for (j = 0 ; j< 3; j ++)
{
printf( <温泉n class =code-string>%d,a [i] [j]);
}
printf( / n);
}
// 转置后的数组
for (i = 0 ; i< 3; i ++)
{
for (j = 0 ; j< 3; j ++)
{
printf( %d,a [j] [i]);
}
printf( / n);
}


 #include<stdio.h>
 #include<conio.h>

 int main()
 {
   int i,j,a[3][3];
   for(i=0;i<3;i++)
   {
     for(j=0;j<3;j++)
     {
       scanf("%d",&a[i][j]);
     }
   }
   //Array Without Transpose
   //Display
   for(i=0;i<3;i++)
   {
     for(j=0;j<3;j++)
     {
       printf("%d",a[i]);
     }
     printf("/n");
   }
   //Array After Transpose
   for(j=0;j<3;j++))																																		
   {
     printf("%d",&a[j]);
   }
   getch();
}

解决方案

A function definition is not a single statement - it always starts and ends with a curly bracket pair.
Then you have a spurious ")" in the "Array After Transpose" for loop.
Try:

#include<stdio.h>
#include<conio.h>
int main()
    {
    int i,j,a[3][3];
    for(i=0;i<3;i++)
        {
        for(j=0;j<3;j++)
            {
            scanf("%d",&a[i][j]);
            }
        }
    //Array Without Transpose
    //Display
    for(i=0;i<3;i++)
        {
        for(j=0;j<3;j++)
            {
            printf("%d",a[i]);
            }
        printf("/n");
        }
    //Array After Transpose
    for(j=0;j<3;j++)
        {
        printf("%d",&a[j]);
        }
    getch();
    }



But do yourself a favour: one character variable names are easy to type, but they don;t tell you what they are used for. For a trivial example like this, it's not a major problem, but if your course starts to build on this, it can become very helpful if you use "proper names" that describe what the data is rather than "a" for example.


Quote:

for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("%d",a[i]);
}
printf("/n");
}
//Array After Transpose
for(j=0;j<3;j++))
{
printf("%d",&a[j]);
}


Should be instead:

for(i=0;i<3;i++)
   {
     for(j=0;j<3;j++)
     {
       printf("%d ",a[i][j]);
     }
     printf("/n");
   }
   //Array After Transpose
   for(i=0;i<3;i++)
   {
     for(j=0;j<3;j++)
     {
       printf("%d ",a[j][i]);
     }
     printf("/n");
   }


这篇关于如何解决DECLARATION SYNTAX ERROR?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆