二級(jí)C程序修改(四)

字號(hào):

===========================================
    試題說明 :
    ===========================================
    函數(shù)fun的功能是:把a(bǔ)數(shù)組中的n個(gè)數(shù)和b數(shù)組中逆序的n個(gè)數(shù)
    一一相減,結(jié)果存在c數(shù)組中。
    例如: 當(dāng)a數(shù)組中的值是:1、3、5、7、8
    b數(shù)組中的值是:2、3、4、5、8
    調(diào)用該函數(shù)后,c中存放的數(shù)據(jù)是:-7、-2、1、4、6
    注意: 部分源程序存在文件PROG1.C中。
    請(qǐng)勿改動(dòng)主函數(shù)main和其它函數(shù)中的任何內(nèi)容,僅在函數(shù)fun
    的花括號(hào)中填入你編寫的若干語句。
    ===========================================
    程序 :
    ===========================================
    #include
    #include
    void fun(int a[], int b[], int c[], int n)
    {
    }
    main()
    { int i, a[100]={1,3,5,7,8}, b[100]={2,3,4,5,8}, c[100];
    clrscr();
    fun(a, b, c, 5);
    printf("The result is: ");
    for (i=0; i<5; i ) printf("%d ", c[i]);
    printf("\n");
    NONO();
    }
    NONO ( )
    {/* 本函數(shù)用于打開文件,輸入數(shù)據(jù),調(diào)用函數(shù),輸出數(shù)據(jù),關(guān)閉文件。 */
    FILE *rf, *wf ;
    int a[100], b[100], c[100], i, j ;
    rf = fopen("in.dat", "r") ;
    wf = fopen("bc02.dat","w") ;
    for(i = 0 ; i < 5 ; i ) {
    for(j = 0 ; j < 5 ; j ) fscanf(rf, "%d,", &a[j]) ;
    for(j = 0 ; j < 5 ; j ) fscanf(rf, "%d,", &b[j]) ;
    fun(a, b, c, 5) ;
    for(j = 0 ; j < 5 ; j ) fprintf(wf, "%d ", c[j]) ;
    fprintf(wf, "\n") ;
    }
    fclose(rf) ;
    fclose(wf) ;
    }
    ===========================================
    所需數(shù)據(jù) :
    ===========================================
    @2 IN.DAT 010
    1,2,3,4,5
    6,7,8,9,10
    2,3,5,6,7
    1,4,6,7,9
    11,7,2,4,8
    8,7,2,3,5
    9,10,3,4,7
    8,11,4,6,8
    4,3,1,9,7
    3,4,8,10,9
    #E
    @3 $BC02.DAT 005
    -9 -7 -5 -3 -1
    -7 -4 -1 2 6
    6 4 0 -3 0
    1 4 -1 -7 -1
    -5 -7 -7 5 4
    #E