2010計算機等考二級C:50套上機程序填空題(20)

字號:

2010計算機等考二級C:50套上機程序填空題(20)

    39、函數(shù)fun的功能是進行數(shù)字字符轉換。若形參ch中是數(shù)字字符'0'~'9', 則'0'轉換成'9','1'轉換成'8','2'轉換成'7',……,'9'轉換成'0';若是其它字符則保持不變;并將轉換后的結果作為函數(shù)值返回。
    請在程序的下劃線處填入正確的內容并把下劃線刪除,使程序得出正確的結果。
    注意:源程序存放在考生文件夾下的BLANK1.C中。
    不得增行或刪行,也不得更改程序的結構!
    #include
    /**********found**********/
    ___1___ fun(char ch)
    {
    /**********found**********/
    if (ch>='0' && ___2___)
    /**********found**********/
    return '9'- (ch-___3___);
    return ch ;
    }
    main()
    { char c1, c2;
    printf("\nThe result :\n");
    c1='2'; c2 = fun(c1);
    printf("c1=%c c2=%c\n", c1, c2);
    c1='8'; c2 = fun(c1);
    printf("c1=%c c2=%c\n", c1, c2);
    c1='a'; c2 = fun(c1);
    printf("c1=%c c2=%c\n", c1, c2);
    }
    40、給定程序中,函數(shù)fun的功能是:找出100~999之間(含100和999)所有整數(shù)中各位上數(shù)字之和為x(x為一正整數(shù))的整數(shù),然后輸出;符合條件的整數(shù)個數(shù)作為函數(shù)值返回。
    例如,當x值為5時,100~999之間各位上數(shù)字之和為5的整數(shù)有:104、113、122、131、140、203、212、221、230、302、311、320、401、410、500。共有15個。當x值為27時,各位數(shù)字之和為27的整數(shù)是:999。只有1個。
    請在程序的下劃線處填入正確的內容并把下劃線刪除, 使程序得出正確的結果。
    注意:源程序存放在考生文件夾下的BLANK1.C中。
    不得增行或刪行,也不得更改程序的結構!
    #include
    int fun(int x)
    { int n, s1, s2, s3, t;
    n=0;
    t=100;
    /**********found**********/
    while(t<=__1__){
    /**********found**********/
    s1=t%10; s2=(__2__)%10; s3=t/100;
    /**********found**********/
    if(s1+s2+s3==__3__)
    { printf("%d ",t);
    n++;
    }
    t++;
    }
    return n;
    }
    main()
    { int x=-1;
    while(x<0)
    { printf("Please input(x>0): "); scanf("%d",&x); }
    printf("\nThe result is: %d\n",fun(x));
    }