作者executor1107 (口责.我受够了)
看板NSYSU-CSE97
标题[作业] 计概作业8-rand,排序,输入输出
时间Wed Dec 8 19:06:02 2004
Edit:把跟这次有关的做了highlight
本来想等到修到可以跑再提出来讨论
但我看等到我自己修到可以跑,大家都毕业了...
边修边讨论吧
Main:
===========================IPIOSORT.cpp========================
#include<stdio.h>
#include<stdlib.h>
#include<sort2.cpp>
int sort();
void main()
{
FILE *finput,*foutput;
int i,total,
transport[total],temp;
printf("Input the number of the numbers:");
scanf("%d",&total);
finput=fopen("input.txt","w+");
if(finput != NULL)
{
for(i=0;i<total;i++)
{
temp=rand();
printf(" %d \n",temp);
fprintf(finput,"%d\n",temp);
}
}
else
printf("Error 01:Couldn't open input.txt in writing phase.");
fclose(finput);
finput=fopen("input.txt","r+");
if(finput != NULL)
{
foutput=fopen("output.txt","w+");
if(foutput != NULL)
{
for(i=0;i<total;i++)
{
fscanf(finput,"%d",&temp);
//fprintf(foutput,"%d\n",temp);
transport[i]=temp;
sort(transport[i],total);
}
}
else
printf("Error 03:Couldn't open output.txt in writing phase.");
}
else
printf("Error 02:Couldn't open input.txt in reading phase.");
//fprintf(foutput,"The %d numbers' average is %f\n",total,avg);
fclose(finput);
fclose(foutput);
}
==================================Sort2.cpp=================================
#include<stdio.h>
sort( transport[total] total )
{
int i, j, total, temp2;
int transport[total];
for(i = 0; i < total; i++) {
for(j = 0; j < total-i; j++) {
if ( transport[j] > transport[j+1] ) {
temp2 = transport[j+1];
transport[j+1] = transport[j];
transport[j] = temp2;
}
}
}
}
每一次都是前一天才讨论实在不好...
这两天我一定要把线代跟微积的弄出来= =
别都是我在写啊...
大家写的好拿出来show off
写的不好,有问题的拿出来讨论咩...
以後一起合作的机会多着,何不从现在开始?:)
--
......ID......
......I am a learning Dancer......
Shake my body through the music...
Dance with the Feel...
This is my ID......
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.117.186.180
※ 编辑: executor1107 来自: 140.117.186.180 (12/08 19:06)
※ 编辑: executor1107 来自: 140.117.186.180 (12/08 20:16)