帮看一个c程序,123陷阱问题

来源:百度知道 编辑:UC知道 时间:2024/06/10 07:28:42
江苏计算机二级的题目。我不知道错在哪里了。

#include "stdio.h"
int fun(long n,long arrary[])
{ int a,b,c=0,i;
long int t,new=n;
if(n==123){arrary[0]=123,rerurn 1;}
for(i=0;new!=123;i++)
{ a=0;b=0;
while(n>0)
{ t=n%10;
if(t%2==0) a++;
else b++;
n=n/10;
}
c=a+b;
arrary[i]=a*100+b*10+c;
new=arrary[i];

}
return i;

}
main()
{
long n;long int arrary[20];
int i,number;
FILE *fp;
printf("\nPlease enter the number which is less than 1000000000:");
scanf("%ld",&n);
number=fun(n,arrary);
fp=fopen("c:\\myf2.out","w");
if(fp==NULL)
{ printf("open myf2.out errpr!\n");
exit(1);
}
for(i=0;i<number;i++)
{ printf("%ld",arrary[i]);fprintf(fp,"%ld\t",a

你想做的究竟是什么呢?看你的程序是计算统计数字中每个数位的偶数和奇数。但是程序又是错误的。只有输入的数字有1个偶数数位和2个奇数数位时才能得到结果,否则是无限循环。
你想让大家改什么呢?

只修改了语法错误,其它的不知道要求,不知道是否需要改

#include "stdio.h"
int fun(long n,long arrary[])
{ int a,b,c=0,i;
long int t,New=n; //new是关键字
if(n==123){arrary[0]=123;return 1;} //rerurn关键字写错了,123后面是分号不是逗号
for(i=0;New!=123;i++) //New
{ a=0;b=0;
while(n>0)
{ t=n%10;
if(t%2==0) a++;
else b++;
n=n/10;
}
c=a+b;
arrary[i]=a*100+b*10+c;
New=arrary[i]; //New

}
return i;

}
main()
{
long n;long int arrary[20];
int i,number;
FILE *fp;
printf("\nPlease enter the number which is less than 1000000000:");
scanf("%ld",&n);
number=fun(n,arrary);
fp=fopen("c:\\myf2.out","w");
if(fp==NULL)
{ printf("open myf2.out errpr!\n");
exit(1);
}