|
論壇說明 |
歡迎您來到『史萊姆論壇』 ^___^ 您目前正以訪客的身份瀏覽本論壇,訪客所擁有的權限將受到限制,您可以瀏覽本論壇大部份的版區與文章,但您將無法參與任何討論或是使用私人訊息與其他會員交流。若您希望擁有完整的使用權限,請註冊成為我們的一份子,註冊的程序十分簡單、快速,而且最重要的是--註冊是完全免費的! 請點擊這裡:『註冊成為我們的一份子!』 |
|
主題工具 | 顯示模式 |
2002-12-10, 06:21 PM | #1 |
|
請問?C語言的這裡要怎ㄇ寫下去..???
各位大大~~我又來請教各位了.....小弟愚昧~~~請多多見諒....QQ"........
這個程式5ㄍ學生比較數學.英文.電算的成績.跟比較名次...5ㄍ人我不知道怎ㄇ比~"~??還有%d 怎ㄇ讓他顯示出來的是小數點~~比較出來的成績怎ㄇ把他丟到陣列去然後一起顯示出來~"~?? #include<stdio.h> void main() { int grade[5][3] = { {80,88,93}, {76,74,81}, {58,66,64}, {63,73,71}, {77,92,90}}; int i , j , sum1,sum2,sum3,sum4,sum5; int ave1,ave2,ave3,ave4,ave5; for (i=0;i<5;i++) { for(j=0;j<3;j++) { printf("%-3d",grade[i][j]); } printf("\n"); } sum1 = grade[0][0] + grade[0][1] + grade[0][2]; ave1 = sum1/3; sum2 = grade[1][0] + grade[1][1] + grade[1][2]; ave2 = sum2/3; sum3 = grade[2][0] + grade[2][1] + grade[2][2]; ave3 = sum3/3; sum4 = grade[3][0] + grade[3][1] + grade[3][2]; ave4 = sum4/3; sum5 = grade[4][0] + grade[4][1] + grade[4][2]; ave5 = sum5/3; printf("The first student's average is ===>%d \n",ave1); printf("The second student's average is ===>%d \n",ave2); printf("The third student's average is ===>%d \n",ave3); printf("The fourth student's average is ===>%d \n",ave4); printf("The fifth student's average is ===>%d \n",ave5); { int sum6,sum7,sum8; int ave6,ave7,ave8; sum6 = grade[0][0] + grade[1][0] + grade[2][0] + grade[3][0] + grade[4][0]; ave6 = sum6/5; sum7 = grade[0][1] + grade[1][1] + grade[2][1] + grade[3][1] + grade[4][1]; ave7 = sum7/5; sum8 = grade[0][2] + grade[1][2] + grade[2][2] + grade[3][2] + grade[4][2]; ave8 = sum8/5; printf("The all class's Math average is ===>%d \n",ave6); printf("The all class's English average is ===>%d \n",ave7); printf("The all class's Electronics average is ===>%d \n",ave8); } } |
送花文章: 0,
|
2002-12-10, 10:29 PM | #2 (permalink) |
長老會員
|
>>還有%d 怎ㄇ讓他顯示出來的是小數點
我記得好像是加%3.2d的樣子 其他的要仔細研究才行ㄋㄟ <不確定,試試啦> |
__________________ 地獄變現記 [人身得來不易,願大家能尊重生命--勿傷胎命][好淫者請好自為之吧--割鳥] 南泉禪師道: 「道不屬知,不屬不知。知是妄覺,不知是無記。若真達不疑之道,猶如太虛,廓然蕩豁,豈可強是非邪?」 德山宣鑒禪師: 「如果明白無事,則勿妄求,妄求而得,亦非得也。汝但無事於心,無心於事,則虛而靈,空而妙。若毛端許,言之本末者,皆為自欺。何故?毫氂繫念,三塗業因。瞥爾情生,萬劫羈鎖。聖名凡號,盡是虛聲。殊相劣形,皆是幻色。汝欲求之,得無累乎?」 |
|
送花文章: 5469,
|
2002-12-12, 05:43 PM | #8 (permalink) |
|
以下程式碼
sum1 = grade[0][0] + grade[0][1] + grade[0][2]; ave1 = sum1/3; sum2 = grade[1][0] + grade[1][1] + grade[1][2]; ave2 = sum2/3; sum3 = grade[2][0] + grade[2][1] + grade[2][2]; ave3 = sum3/3; sum4 = grade[3][0] + grade[3][1] + grade[3][2]; ave4 = sum4/3; sum5 = grade[4][0] + grade[4][1] + grade[4][2]; ave5 = sum5/3; 改成 sum1 = grade[0][0] + grade[0][1] + grade[0][2]; ave1 =(float) sum1/3; sum2 = grade[1][0] + grade[1][1] + grade[1][2]; ave2 = (float)sum2/3; sum3 = grade[2][0] + grade[2][1] + grade[2][2]; ave3 = (float)sum3/3; sum4 = grade[3][0] + grade[3][1] + grade[3][2]; ave4 = (float)sum4/3; sum5 = grade[4][0] + grade[4][1] + grade[4][2]; ave5 = (float)sum5/3; 試試看 記得最後要printf的時候,要把%d改成%f應該就可以了吧 |
送花文章: 0,
|
2002-12-13, 03:39 PM | #11 (permalink) |
|
#include <stdio.h>
void main() { int num[6][5],po[6]; int sum1,sum2,i,j,temp; printf("\1: 請輸入成績 \n"); for ( i = 0; i < 5; i++ ) for ( j = 0; j < 3; j++ ) scanf("%d",&num[i][j]); for ( i = 0; i < 5; i++ ) { sum1 = 0; for ( j = 0; j < 3; j++ ) sum1 += num[i][j]; num[i][3] = sum1 / 3; } for ( i = 0; i < 5; i++ ) { po[i] = num[i][3]; } for ( i = 0; i < 4; i++ ) for ( j = i + 1; j < 5; j++ ) if ( po[i] < po[j] ) { temp = po[i]; po[i] = po[j]; po[j] = temp; } for ( i = 0; i < 5; i++ ) { if ( num[i][3] == po[0] ) num[i][4] = 1; else if ( num[i][3] == po[1] ) num[i][4] = 2; else if ( num[i][3] == po[2] ) num[i][4] = 3; else if ( num[i][3] == po[3] ) num[i][4] = 4; else if ( num[i][3] == po[4] ) num[i][4] = 5; } for ( j = 0; j < 4; j++ ) { sum2 = 0; for ( i = 0; i < 5; i++ ) sum2 += num[i][j]; num[5][j] = sum2 / 5; } num[5][4]=0; for ( i = 0; i < 6; i++ ) printf("\2:%d %d %d %d %d \n",num[i][0],num[i][1],num[i][2],num[i][3],num[i][4]); } ============================================== <--這是同學滴答案...可是我不想抄襲~~我滴問題只剩下如何把ave1~5一起丟進陣列裡= =....排名要怎ㄇ讓他排出來(也是丟到陣列裡讓程式自己排名次) |
送花文章: 0,
|
2002-12-13, 03:47 PM | #12 (permalink) |
|
#include<stdio.h>
void main() { int grade[5][5] = { {80,88,93}, {76,74,81}, {58,66,64}, {63,73,71}, {77,92,90}}; int i , j , sum1,sum2,sum3,sum4,sum5; float ave1,ave2,ave3,ave4,ave5; for (i=0;i<5;i++) { for(j=0;j<3;j++) { printf("%-3d",grade[i][j]); } printf("\n"); } sum1 = grade[0][0] + grade[0][1] + grade[0][2]; ave1 = (float)sum1/3; sum2 = grade[1][0] + grade[1][1] + grade[1][2]; ave2 = (float)sum2/3; sum3 = grade[2][0] + grade[2][1] + grade[2][2]; ave3 = (float)sum3/3; sum4 = grade[3][0] + grade[3][1] + grade[3][2]; ave4 = (float)sum4/3; sum5 = grade[4][0] + grade[4][1] + grade[4][2]; ave5 = (float)sum5/3; printf("The first student's average is ===>%3.2f \n",ave1); printf("The second student's average is ===>%3.2f \n",ave2); printf("The third student's average is ===>%3.2f \n",ave3); printf("The fourth student's average is ===>%3.2f \n",ave4); printf("The fifth student's average is ===>%3.2f \n",ave5); { int sum6,sum7,sum8; float ave6,ave7,ave8; sum6 = grade[0][0] + grade[1][0] + grade[2][0] + grade[3][0] + grade[4][0]; ave6 = (float)sum6/5; sum7 = grade[0][1] + grade[1][1] + grade[2][1] + grade[3][1] + grade[4][1]; ave7 = (float)sum7/5; sum8 = grade[0][2] + grade[1][2] + grade[2][2] + grade[3][2] +grade[4] [2] ave8 = (float)sum8/5; printf("The all class's Math average is ===>%3.2f \n",ave6); printf("The all class's English average is ===>%3.2f \n",ave7); printf("The all class's Electronics average is ===>%3.2f\n",ave8); } { int i,j,tmp; int num[5] = {ave1,ave2,ave3,ave4,ave5}; for(i=0;i<2;i++) { for( j=0;j<4;j++) if (num[j]>num[j+1]) { tmp = num[j]; num[j]=num[j+1]; num[j+1] = tmp; } printf("\2:loop %d ",i); for(j=0;j<5;j++) printf("%4d",num[j]); printf("\n"); } printf("\2:排名 %d %d %d %d %d \n",5,4,3,2,1); } } ============================================== 這ㄍ是小弟滴程式........= =''請幫忙想辦法一下~~~~拜託ㄌ.......我一直丟不進ㄑ~~QQ"~~~ |
送花文章: 0,
|
2002-12-14, 12:17 AM | #13 (permalink) |
|
#include<stdio.h>
void main() { int grade[5][5] = { {80,88,93}, {76,74,81}, {58,66,64}, {63,73,71}, {77,92,90}}; int i , j , sum1,sum2,sum3,sum4,sum5; float ave[8]; for (i=0;i<5;i++) { for(j=0;j<3;j++) { printf("%-3d",grade[i][j]); } printf("\n"); } sum1 = grade[0][0] + grade[0][1] + grade[0][2]; ave[0] = (float)sum1/3; sum2 = grade[1][0] + grade[1][1] + grade[1][2]; ave[1] = (float)sum2/3; sum3 = grade[2][0] + grade[2][1] + grade[2][2]; ave[2] = (float)sum3/3; sum4 = grade[3][0] + grade[3][1] + grade[3][2]; ave[3] = (float)sum4/3; sum5 = grade[4][0] + grade[4][1] + grade[4][2]; ave[4] = (float)sum5/3; printf("The first student's average is ===>%3.2f \n",ave[0]); printf("The second student's average is ===>%3.2f \n",ave[1]); printf("The third student's average is ===>%3.2f \n",ave[2]); printf("The fourth student's average is ===>%3.2f \n",ave[3]); printf("The fifth student's average is ===>%3.2f \n",ave[4]); { int sum6,sum7,sum8; sum6 = grade[0][0] + grade[1][0] + grade[2][0] + grade[3][0] + grade[4][0]; ave[5] = (float)sum6/5; sum7 = grade[0][1] + grade[1][1] + grade[2][1] + grade[3][1] + grade[4][1]; ave[6] = (float)sum7/5; sum8 = grade[0][2] + grade[1][2] + grade[2][2] + grade[3][2] +grade[4][2]; ave[7] = (float)sum8/5; printf("The all class's Math average is ===>%3.2f \n",ave[5]); printf("The all class's English average is ===>%3.2f \n",ave[6]); printf("The all class's Electronics average is ===>%3.2f\n",ave[7]); } { int i,j,tmp; int num[5]; for(i=0;i<5;i++) num[i]=ave[i]; for(i=0;i<2;i++) { for( j=0;j<4;j++) if (num[j]>num[j+1]) { tmp = num[j]; num[j]=num[j+1]; num[j+1] = tmp; } printf("\2:loop %d ",i); for(j=0;j<5;j++) printf("%4d",num[j]); printf("\n"); } printf("\2:排名 %d %d %d %d %d \n",5,4,3,2,1); } } 可以了吧.......不懂再來問 |
送花文章: 0,
|
|
|
相似的主題 | ||||
主題 | 主題作者 | 討論區 | 回覆 | 最後發表 |
請問各位大大≧▽≦這符號要怎ㄇ打ㄚ | tonydavi | 一般電腦疑難討論區 | 3 | 2003-03-22 12:53 AM |
請問bin黨要怎ㄇ開啟ㄋ | nick289 | 軟體應用問題討論區 | 1 | 2003-01-05 06:07 PM |
請問我有砍步調ㄉ檔案要怎ㄇ半~ | huangtsung | 一般電腦疑難討論區 | 0 | 2002-12-27 03:06 PM |