●●●C语言+200分排错●●●

来源:百度知道 编辑:UC知道 时间:2024/06/19 18:52:19
#include<stdio.h>
#include<math.h>

void main()
{
int checkit(int l[],int m);
void putoutit(int a[],int m);
int n;
int k;
k=1;
scanf("%d",&n);
int x[n]={0};
while(k>0)
{
x[k]=x[k]+1;
while(x[k]<=n&&!checkit(x,k)
x[k]=x[k]+1;
if(x[k]<=n)
{
if(k=n)
putoutit(x[n],n);
else
k=k+1;
}
else
{
x[k]=0;
k=k-1;
}
}

}

int checkit(int l[],int m)
{
int blloen=1;
for(int i=1;i<=m;i++)
{
if(l[i]!l[m]&&(abs(l[m]-l[i])!=abs(m-i))
return blloen=1;
else
return blloen=0;
}
}
void putoutit(int a[],int m)
{
for(int i=0;i<m;i++)
printf(%d,a[i]);
}
-----------------------------------
NQUEEN.c
NQUEEN.c(9) : warning C4996: “scanf”被声明为否决的
d:\Pr

人很多哦 呵呵 我也来凑凑热闹

#include<stdio.h>
#include<math.h> /*声明所需的头文件*/
#define N 10 /*文件开头定义数组大小,方便修改,不能靠输入一个n来确定数组大小*/

int checkit(int a[],int m);
void putoutit(int a[],int m); /*在主函数之前对所需用的函数进行声明,其实建议把非主函数写在主函数之前*/

int main(int argc,char *argv[]) /*主函数*/
{
int k=1; /*定义k并赋初值*/
int x[N]={0}; /*定义数组并给数组赋值*/
while(k>0)
{
x[k]+=1; /*等价于x[k]=x[k]+1*/
while(x[k]<N&&!checkit(x,k))
{
x[k]+=1; /*同上*/
}
if(x[k]<=N)
{
if(x[k]==N)