帮我看下这道题错哪里了?求详解,谢谢
#include<stdio.h>#defineMAX200inta[MAX],b[MAX],cnt=0;voidjsVal()*********************...
#include <stdio.h>
#define MAX 200
int a[MAX], b[MAX], cnt = 0;
void jsVal()
*********************************(我补充的部分)
{int qw,bw,sw,gw,i,j,tem;
for(i=0;i<200;i++)
{qw=a[i]/1000;
bw=a[i]%10/100;
sw=a[i]%100/10;
gw=a[i]%10;
if(qw&&(gw-qw-bw-sw)>=0&&a[i]%2==0)
b[cnt++]=a[i];
}
for(i=0;i<cnt-1;i++)
for(j=i+1;j<cnt;j++)
if(b[i]>b[j])
{tem=b[i];b[i]=b[j];b[j]=tem;}
***************************
}
void readDat()
{
int i;
FILE *fp;
fp = fopen("IN.DAT", "r");
for (i=0; i<MAX; i++)
fscanf(fp, "%d,", &a[i]);
fclose(fp);
}
void writeDat()
{
FILE *fp;
int i;
fp = fopen("OUT.DAT", "w");
fprintf(fp, "%d\n", cnt);
for (i=0; i<cnt; i++)
fprintf(fp, "%d\n", b[i]);
fclose(fp);
}
void main()
{
int i;
readDat();
jsVal();
printf("满足条件的数=%d\n", cnt);
for (i=0; i<cnt; i++)
printf("%d ", b[i]);
printf("\n");
writeDat();
} 展开
#define MAX 200
int a[MAX], b[MAX], cnt = 0;
void jsVal()
*********************************(我补充的部分)
{int qw,bw,sw,gw,i,j,tem;
for(i=0;i<200;i++)
{qw=a[i]/1000;
bw=a[i]%10/100;
sw=a[i]%100/10;
gw=a[i]%10;
if(qw&&(gw-qw-bw-sw)>=0&&a[i]%2==0)
b[cnt++]=a[i];
}
for(i=0;i<cnt-1;i++)
for(j=i+1;j<cnt;j++)
if(b[i]>b[j])
{tem=b[i];b[i]=b[j];b[j]=tem;}
***************************
}
void readDat()
{
int i;
FILE *fp;
fp = fopen("IN.DAT", "r");
for (i=0; i<MAX; i++)
fscanf(fp, "%d,", &a[i]);
fclose(fp);
}
void writeDat()
{
FILE *fp;
int i;
fp = fopen("OUT.DAT", "w");
fprintf(fp, "%d\n", cnt);
for (i=0; i<cnt; i++)
fprintf(fp, "%d\n", b[i]);
fclose(fp);
}
void main()
{
int i;
readDat();
jsVal();
printf("满足条件的数=%d\n", cnt);
for (i=0; i<cnt; i++)
printf("%d ", b[i]);
printf("\n");
writeDat();
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询