在输出前进行了一个循环并且赋值,这个值与输出结果无关但是却导致了输出结果不一致
#include<stdio.h>
int main()
{
int n,a[30],b[30],c[30],d=0,ans;
a[1]=0;
b[1]=1;
c[1]=1;
for(int i=2;i<=30;i++)
{
a[i]=0;
b[i]=0;
c[i]=0;
}
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
for(int j=1;j<=30;j++)
{
c[j]=a[j]+b[j];
c[j]=c[j]+d;
if(c[j]>9)
{
d=c[j]/10;
c[j]=c[j]%10;
}
else d=0;
}
for(int j=1;j<=30;j++)
{
a[j]=b[j];
}
for(int j=1;j<=30;j++)
{b[j]=c[j];
}
}
for(int p=20;p>0;p--)
{
ans++;
}
for(int i=30;i>0;i--)
{
printf("%d",c[i]);
}
return 0;
}
#include<stdio.h>
int main()
{
int n,a[30],b[30],c[30],d=0,ans;
a[1]=0;
b[1]=1;
c[1]=1;
for(int i=2;i<=30;i++)
{
a[i]=0;
b[i]=0;
c[i]=0;
}
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
for(int j=1;j<=30;j++)
{
c[j]=a[j]+b[j];
c[j]=c[j]+d;
if(c[j]>9)
{
d=c[j]/10;
c[j]=c[j]%10;
}
else d=0;
}
for(int j=1;j<=30;j++)
{
a[j]=b[j];
}
for(int j=1;j<=30;j++)
{b[j]=c[j];
}
}
for(int p=20;p>0;p--)
{
// ans++;
}
for(int i=30;i>0;i--)
{
printf("%d",c[i]);
}
return 0;
}
两段代码仅有42行的ans++是否被注释不一致
所用软件为最新官网下载的code blocks
编译器位GNU GCC