作者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)