作者Isuzel (Isuzel)
看板NSYSU-CSE97
標題Re: [作業] 計概作業8-rand,排序,輸入輸出
時間Wed Dec 8 20:19:14 2004
※ 引述《executor1107 (口責.我受夠了)》之銘言:
: 本來想等到修到可以跑再提出來討論
: 但我看等到我自己修到可以跑,大家都畢業了...
: 邊修邊討論吧
: Main:
: ===========================IPIOSORT.cpp========================
: #include<stdio.h>
: #include<stdlib.h>
: #include<sort2.cpp>
include的規則:
1. #include<****.h>
會到./include/下面去找
2. #include"****.c"
會到程式所在的目錄去找
: 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 )
sort的引數?
這個引數我看不太懂,有人要說明一下嗎?
: {
: 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
: 寫的不好,有問題的拿出來討論咩...
: 以後一起合作的機會多著,何不從現在開始?:)
+1
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.117.186.150