求N*N矩阵对角线元素之和,需不需要分奇偶性讨论,这个代码的错误怎么改正?
#include<stdio.h>
#include<stdlib.h>
int main(int argc,char *argv[])
{
int N;
printf("input N:");
scanf("%d",&N);
int a[N][N];
int i,j;
printf("input a[N][N]:/n");
for(i=0;i<N;i++)
for(j=0;j<N;j++)
scanf("%d",&a[i][j]);
int num=0;
for(i=0;i<N;i++)
for(j=0;j<N;j++)
if(i==j||i+j==N-1)
{
num+=a[i][j];
}
for(i=0;i<N;i++)
{
for(j=0;j<N;j++)
{
printf("%d/t",a[i][j]);
}
printf("/n");
}
printf("%d/n",num);
return 0;
}
Compiling...
133.c
C:\Users\DELL\Desktop\宝儿\133.c(10) : error C2143: syntax error : missing ';' before 'type'
C:\Users\DELL\Desktop\宝儿\133.c(11) : error C2143: syntax error : missing ';' before 'type'
C:\Users\DELL\Desktop\宝儿\133.c(13) : error C2065: 'i' : undeclared identifier
C:\Users\DELL\Desktop\宝儿\133.c(14) : error C2065: 'j' : undeclared identifier
C:\Users\DELL\Desktop\宝儿\133.c(15) : error C2065: 'a' : undeclared identifier
C:\Users\DELL\Desktop\宝儿\133.c(15) : error C2109: subscript requires array or pointer type
C:\Users\DELL\Desktop\宝儿\133.c(15) : error C2109: subscript requires array or pointer type
C:\Users\DELL\Desktop\宝儿\133.c(15) : error C2102: '&' requires l-value
C:\Users\DELL\Desktop\宝儿\133.c(16) : error C2143: syntax error : missing ';' before 'type'
C:\Users\DELL\Desktop\宝儿\133.c(21) : error C2065: 'num' : undeclared identifier
C:\Users\DELL\Desktop\宝儿\133.c(21) : error C2109: subscript requires array or pointer type
C:\Users\DELL\Desktop\宝儿\133.c(21) : error C2109: subscript requires array or pointer type
C:\Users\DELL\Desktop\宝儿\133.c(27) : error C2109: subscript requires array or pointer type
C:\Users\DELL\Desktop\宝儿\133.c(27) : error C2109: subscript requires array or pointer type
执行 cl.exe 时出错.
向大佬们请教,万分感谢!