Re: [問題] 條件式判斷

看板C_and_CPP作者 (寂寞讓人失去理智)時間15年前 (2011/02/11 00:39), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串6/8 (看更多)
※ 引述《doggingg (doggingg)》之銘言: : There are 4 tests for 10 students with grade ranges as: : A:(grade>=90) : B:(90>grade>=80) : C:(80>grade>=70) : D:(70>grade>=60) : E:(grade<60) : write a nested loop to count the number of grades, : eg. 10'A's , 15'B's,etc and put the results into sc[5] : (you can not use if statement) : 題目是說10個同學每人有四個成績共40個成績,計算A等級幾個,B等級幾個 : 把這五個等級的個數放進sc陣列中, : 我想請教的是,不用if寫,要怎麼寫,是用switch嗎? 還是?: #include <stdio.h> int main() { int sign=0; int i,x[40]={0}; int sc[6]={0}; printf("請輸入10位學生共40個成績\n"); for(i=0;i<40;i++){ scanf("%d",&x[i]); x[i]=x[i]/10; x[i]=x[i]-5; sign=x[i]&(1<<31); sign=(sign>>31)+1; x[i]=x[i]*sign; sc[x[i]]=sc[x[i]]+1; } sc[4]=sc[4]+sc[5]; printf("A等級%d位 \n",sc[4]); printf("B等級%d位 \n",sc[3]); printf("C等級%d位 \n",sc[2]); printf("D等級%d位 \n",sc[1]); printf("E等級%d位 \n",sc[0]); system("pause"); return 0; } 這是我的寫法…應該沒用到判斷式吧?@@ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 115.43.155.73
文章代碼(AID): #1DL1JJVi (C_and_CPP)
討論串 (同標題文章)
文章代碼(AID): #1DL1JJVi (C_and_CPP)