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