- 最後登錄
- 2024-3-29
- 在線時間
- 0 小時
- 註冊時間
- 2016-8-22
- 閱讀權限
- 20
- 精華
- 0
- UID
- 16624936
- 帖子
- 61
- 積分
- 49 點
- 潛水值
- 26590 米
| 成為伊莉的版主,你將獲得更高級和無限的權限。把你感興趣的版面一步步地發展和豐盛,那種滿足感等著你來嚐嚐喔。 第六題(若3的倍數為累減請乘-1)- int count1 = 0,count2=0,count3=0;
- int sum1 = 0, sum2 = 0, sum3 = 0;
- int intInput = 1;
- while (intInput>0)
- {
- string input = Console.ReadLine();
- if (int.TryParse(input, out intInput) && intInput>0)
- {
- if (intInput % 3 == 0 && intInput % 5 == 0)//3及5的倍數
- {
- count3++;
- sum3 += intInput;
- }
- else if (intInput % 5 == 0)//5的倍數
- {
- count2++;
- sum2 += intInput;
- }
- else if (intInput % 3 == 0)//3的倍數
- {
- count1++;
- sum1 += intInput;
- }
- }
- }
- Console.WriteLine("3的倍數個數{0},累加值{1}",count1,sum1);
- Console.WriteLine("5的倍數個數{0},累加值{1}", count2, sum2);
- Console.WriteLine("3及5的倍數個數{0},累加值{1}", count3, sum3);
複製代碼 第七題- int chinese = 0, english = 0;
- int count1 = 0,count2=0;
- int both = 0;
- int avg = 0;
- int i = 1;
- do
- {
- int j=1;
- do{
- Console.WriteLine("請輸入第{0}位學生{1}成績:", i, (j == 2) ? "英文" : "國文");
- string input = Console.ReadLine();
- int temp = 0;
- if (int.TryParse(input, out temp))
- {
- if (j == 1)
- {
- chinese = temp;
- }
- else
- {
- english = temp;
- }
- }
- j++;
-
- }while(j<=2);
- if (chinese < 60 && english < 60) both++;
- if (chinese < 60) count1++;
- if (english < 60) count2++;
- if ((chinese + english) / 2 < 60) avg++;
- i++;
- } while (i <= 4);
- Console.WriteLine("國文不及格人數{0}人" , count1);
- Console.WriteLine("英文不及格人數{0}人" , count2);
- Console.WriteLine("兩科皆不及格人數{0}人" , both);
- Console.WriteLine("平均不及格人數{0}人" , avg);
複製代碼 ... |
|