SHOW:
|
|
- or go back to the newest paste.
| 1 | /*------------------------------------------------------------------------------ | |
| 2 | HELLO.C | |
| 3 | Copyright 1995-1999 Keil Software, Inc. | |
| 4 | ------------------------------------------------------------------------------*/ | |
| 5 | #include <REG52.H> /* special function register declarations */ | |
| 6 | /* for the intended 8051 derivative */ | |
| 7 | #include <stdio.h> /* prototype declarations for I/O functions */ | |
| 8 | #ifdef MONITOR51 /* Debugging with Monitor-51 needs */ | |
| 9 | char code reserve [3] _at_ 0x23; /* space for serial interrupt if */ | |
| 10 | #endif /* Stop Exection with Serial Intr. */ | |
| 11 | /* is enabled */ | |
| 12 | ||
| 13 | void swap(int *a, int *b) | |
| 14 | {
| |
| 15 | int tmp=*b; | |
| 16 | *b = *a; | |
| 17 | *a = tmp; | |
| 18 | ||
| 19 | } | |
| 20 | ||
| 21 | /*------------------------------------------------ | |
| 22 | The main C function. Program execution starts | |
| 23 | here after stack initialization. | |
| 24 | ------------------------------------------------*/ | |
| 25 | int main (void) | |
| 26 | - | { //=============�ܼƽЫŧi��U��=============//
|
| 26 | + | { //=============變數請宣告於下方=============//
|
| 27 | int score[2][10]={{0},{0}};
| |
| 28 | int i,j,count=0; | |
| 29 | ||
| 30 | /*------------------------------------------------ | |
| 31 | - | �]�w��C��(19200 BAUD 11.0592MHZ) |
| 31 | + | 設定串列埠(19200 BAUD 11.0592MHZ) |
| 32 | ------------------------------------------------*/ | |
| 33 | - | #ifndef MONITOR51 /*�]�w��C��(19200 BAUD 11.0592MHZ) */ |
| 33 | + | #ifndef MONITOR51 /*設定串列埠(19200 BAUD 11.0592MHZ) */ |
| 34 | SCON = 0x50; /* SCON: mode 1, 8-bit UART, enable rcvr */ | |
| 35 | TMOD |= 0x20; /* TMOD: timer 1, mode 2, 8-bit reload */ | |
| 36 | TH1 = 0xfd; /* TH1: reload value for 9600 baud @ 11.0592MHZ */ | |
| 37 | PCON |= 0x80; /* SMOD=1: Double the baud rate to 19200 @ 11.0592MHZ */ | |
| 38 | TR1 = 1; /* TR1: timer 1 run */ | |
| 39 | TI = 1; /* TI: set TI to send first char of UART */ | |
| 40 | #endif | |
| 41 | /*------------------------------------------------ | |
| 42 | Note that an embedded program never exits (because | |
| 43 | there is no operating system to return to). It | |
| 44 | must loop and execute forever. | |
| 45 | ------------------------------------------------*/ | |
| 46 | - | //=============�{���X��g��U��=============//
|
| 46 | + | //=============程式碼請撰寫於下方=============// |
| 47 | ||
| 48 | - | printf("��J�Ǹ� �b��J���� �@�Q��:\n");
|
| 48 | + | printf("輸入學號 在輸入分數 共十組:\n");
|
| 49 | for(i=0;i<10;i++) | |
| 50 | scanf("%d%d",&score[0][i],&score[1][i]);
| |
| 51 | ||
| 52 | ||
| 53 | for(i=10;i>0;i--) {
| |
| 54 | for(j=0;j<i-1;j++) {
| |
| 55 | if(score[1][j]>score[1][j+1]){
| |
| 56 | swap(&score[0][j], &score[0][j+1]); | |
| 57 | swap(&score[1][j], &score[1][j+1]); | |
| 58 | count++; | |
| 59 | } | |
| 60 | } | |
| 61 | } | |
| 62 | - | printf("\n�Ѥp�ƨ�j��:\n�Ǹ�\t����\n");
|
| 62 | + | printf("\n由小排到大後:\n學號\t分數\n");
|
| 63 | for(i=0;i<10;i++) | |
| 64 | printf("%d\t%d\n", score[0][i],score[1][i] );
| |
| 65 | printf("%d",count);
| |
| 66 | ||
| 67 | while(1); | |
| 68 | ||
| 69 | - | }//=====================�{���X����=====================// |
| 69 | + | }//=====================程式碼結束=====================// |