Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- int main(void)
- {
- int i,j;
- int no[10]; //no[10]放數字的陣列
- int count=1; //記錄共幾個點
- int tmp; //位置對調時所需的暫存參數
- ////////////////////讀檔///////////////////////
- printf("**讀檔**\n");
- FILE *read;
- int b;
- read=fopen("random.txt","r");
- printf("開出的號碼有:\n");
- while((fscanf(read,"%d",&b))!=EOF)
- {
- no[count]=b;
- printf("%d\n",no[count]);
- count++;
- }
- printf("==========讀檔完成 =============\n\n");
- ////////////////排序////////////////////
- printf("==========排序 =============\n\n");
- for(i=1;i<count;i++)
- {
- for(j=i+1;j<count;j++)
- {
- if(no[i]>no[j])
- {
- tmp=no[j];
- no[j]=no[i];
- no[i]=tmp;
- }
- }
- }
- printf("==========排序完成 =============\n\n");
- printf("由小至大:");
- for(j=1;j<count;j++)
- {
- printf("%d ",no[j]);
- }
- printf("\n\n");
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement