Report#2【補足1】

  1. 例題 balance.c
    /*
      Program    : balance.c
      Student-ID : 053772A
      Author     : TANIGUCHI,Yuji
      UpDate     : 2005/04/27(Wed)
      Comments   : Payment & Balance
    */
     
    #include <stdio.h>
     
    int main()
    {
      int price = 1234, pay = 10000;
      int balance, amount;
     
    /******************************* scanf */
      printf("Price?   => "); scanf("%d",&price);
      printf("Payment? => "); scanf("%d",&pay);
      printf("----\n");
     
    /******************************* balance */
      balance = pay - price;
      printf("price = %d, ",price);
      printf("payment = %d, balance = %d\n",pay,balance);
      printf("----\n");
     
    /******************************* 5000-yen */
      amount  = balance / 5000;
      balance = balance % 5000;
      printf("5000-yen note = %d\n",amount);
     
      return(0);
    }

問題:お釣りの5円と1円の計算において、次のコードを読み、以下の問いに答えよ。

  1. Code#A
    /******************************* 5-yen */
      amount  = balance / 5;
      balance = balance % 5;
      printf("5-yen coin = %d\n",amount);
     
    /******************************* 1-yen */
      amount  = balance / 1;
      balance = balance % 1;
      printf("1-yen coin = %d\n",amount);
  2. Code#B
    /******************************* 5-yen */
      amount  = balance / 5;
      balance = balance % 5;
      printf("5-yen coin = %d\n",amount);
     
    /******************************* 1-yen */
      printf("1-yen coin = %d\n",amount);
  3. Code#C
    /******************************* 5-yen */
      amount  = balance / 5;
      balance = balance % 5;
      printf("5-yen coin = %d\n",amount);
     
    /******************************* 1-yen */
      printf("1-yen coin = %d\n",balance);
  4. Code#D
    /******************************* 5-yen */
      amount  = balance / 5;
      balance = balance % 5;
      printf("5-yen coin = %d\n",amount);
     
    /******************************* 1-yen */
      amoount = balance;
      printf("1-yen coin = %d\n",amount);

問1:明らかに間違っているコードは?

選択肢 投票
Code#A 0  
Code#B 2  
Code#C 16  
Code#D 9  

問2:一番無駄の多いコードは?

選択肢 投票
Code#A 22  
Code#B 0  
Code#C 0  
Code#D 0  

問3:最も適切なコードは?

選択肢 投票
Code#A 1  
Code#B 16  
Code#C 22  
Code#D 0  


トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2015-05-14 (木) 13:34:23 (1590d)