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=0; //記錄共幾個數字
- int tmp; //位置對調時所需的暫時參數
- ////////////////////讀檔///////////////////////////
- printf("**讀檔**\n\n");
- FILE *read;
- int b;
- read = fopen("random.txt","r");
- printf("開出的號碼有:\n");
- while((fscanf(read,"%d",&b))!=EOF)
- {
- count++;
- no[count]=b;
- printf("%d, ",no[count]);
- }
- printf("\n\n==========讀檔完成==============\n\n");
- ////////////////排序/////////////////////////////////
- printf("*************排序**********\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;
- }
- }
- }
- for(i=1;i<=count;i++)
- printf("%d, ",no[i]);
- printf("\n\n");
- //////////////////// 將16刪除///////////////////
- printf("\n\n**********16刪除*************\n\n");
- for(i=1;i<=count;i++)
- {
- if (no[i]==16)
- {
- for(j=1;j<count;j++)
- {
- no[j]=no[j+1];
- }
- }
- }
- for(i=1;i<count+1;i++)
- printf("%d, ",no[i]);
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment