V C++ 为什么一定要有return count
#include<stdio.h>#include<string.h>#include<conio.h>typedefstruct{intx1,x2,x3;}data;d...
#include <stdio.h>
#include <string.h>
#include <conio.h>
typedef struct
{ int x1, x2, x3;
} data;
data aa[200], bb[200];
int greatSort()
{ int i, j, count = 0;
data val;
for (i=0; i<200; i++)
if (aa[i].x1 > aa[i].x2+aa[i].x3)
{ bb[count] = aa[i];
count++;
}
for (i=0; i<count-1; i++)
for (j=i+1; j<count; j++)
if (bb[i].x1+bb[i].x3 > bb[j].x1+bb[j].x3)
{ val = bb[i];
bb[i] = bb[j];
bb[j] = val;
}
return count;
}
void Rdata()
{ FILE *in;
int i;
in = fopen("IN.dat", "r");
for (i=0; i<200; i++)
fscanf(in, "%d %d %d", &aa[i].x1, &aa[i].x2, &aa[i].x3);
fclose(in);
}
void Wdata(int count)
{ FILE *out;
int i;
out = fopen("OUT.dat", "w");
for (i=0; i<count; i++)
{ printf("%d,%d,%d第一个数+第三个数=%d\n",bb[i].x1, bb[i].x2, bb[i].x3, bb[i].x1 + bb[i].x3);
fprintf(out, "%d %d %d\n", bb[i].x1, bb[i].x2, bb[i].x3);
}
fclose(out);
}
void main()
{ int count;
Rdata();
count = greatSort(); /* 返回满足条件的个数 */
Wdata(count);
}
我就是不太明白为什么多一个return count 和少一个return count 结果就是不一样,并且答案是必须要这个return count;请高手们告诉我一下,谢谢!急。 展开
#include <string.h>
#include <conio.h>
typedef struct
{ int x1, x2, x3;
} data;
data aa[200], bb[200];
int greatSort()
{ int i, j, count = 0;
data val;
for (i=0; i<200; i++)
if (aa[i].x1 > aa[i].x2+aa[i].x3)
{ bb[count] = aa[i];
count++;
}
for (i=0; i<count-1; i++)
for (j=i+1; j<count; j++)
if (bb[i].x1+bb[i].x3 > bb[j].x1+bb[j].x3)
{ val = bb[i];
bb[i] = bb[j];
bb[j] = val;
}
return count;
}
void Rdata()
{ FILE *in;
int i;
in = fopen("IN.dat", "r");
for (i=0; i<200; i++)
fscanf(in, "%d %d %d", &aa[i].x1, &aa[i].x2, &aa[i].x3);
fclose(in);
}
void Wdata(int count)
{ FILE *out;
int i;
out = fopen("OUT.dat", "w");
for (i=0; i<count; i++)
{ printf("%d,%d,%d第一个数+第三个数=%d\n",bb[i].x1, bb[i].x2, bb[i].x3, bb[i].x1 + bb[i].x3);
fprintf(out, "%d %d %d\n", bb[i].x1, bb[i].x2, bb[i].x3);
}
fclose(out);
}
void main()
{ int count;
Rdata();
count = greatSort(); /* 返回满足条件的个数 */
Wdata(count);
}
我就是不太明白为什么多一个return count 和少一个return count 结果就是不一样,并且答案是必须要这个return count;请高手们告诉我一下,谢谢!急。 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询