ducktw
|
分享:
▲
1.#include <stdio.h> /* 氣泡排序法 Bubble Sort */
void main(void) { int data[50]; int i,j,n,temp;
printf("輸入數值的個數: "); /*輸入n */ scanf("%d" ,&n); printf("\n"); if (n > 49) { printf("請輸入小於49的數字\n"); return; } for (i = 1;i <= n;i++) { /*輸入 n 個數值 */ printf("請輸入數值:"); printf("data[%d]=", i); scanf("%d", &data); } for (i=1; i <= n; i++) { for (j = n; j > i; j--) { if (data[j-1] > data[j]) { /*若 data[j-1] > data[j],則兩個值交換 */ temp = data[j-1]; data[j-1] = data[j]; data[j] = temp; } } } printf("\n資料排序後為\n"); for (i = 1; i <= n; i++) { printf("%d ", data); } }
2.#include <stdio.h> #include <stdlib.h> #include <string.h>
int main(void) { int qty = 0; int qtycnt = 1; //計算人數迴圈用(兼最後顯示迴圈用) int i = 0; int studren[50]={0}; char tot[][57]={" 100 :","90-99 :","80-89 :","70-79 :","60-69 :","50-59 :", "40-49 :","30-39 :","20-29 :","10-19 :"," 0- 9 :"}; char tmt[][57]={" 100 :","90-99 :","80-89 :","70-79 :","60-69 :","50-59 :", "40-49 :","30-39 :","20-29 :","10-19 :"," 0- 9 :"}; while(1) { printf("\n請輸入學生人數(最多 50 人,輸入 0 結束):"); scanf("%d",&qty); if(qty==0) break;
if(qty > 0 && qty <= 50) { printf("請輸入學生分數\n"); for( qtycnt=1 ; qtycnt<=qty ; qtycnt++ ) { while(1) { printf("第 %d 位 : ",qtycnt); scanf("%d",&studren[qtycnt]); if(studren[qtycnt] >= 0 && studren[qtycnt] <= 100) { if(studren[qtycnt]==0) { strcat(tot[10],"="); break; } else { switch(studren[qtycnt]/10) { case 10: strcat(tot[0],"="); break; case 9: strcat(tot[1],"="); break; case 8: strcat(tot[2],"="); break; case 7: strcat(tot[3],"="); break; case 6: strcat(tot[4],"="); break; case 5: strcat(tot[5],"="); break; case 4: strcat(tot[6],"="); break; case 3: strcat(tot[7],"="); break; case 2: strcat(tot[8],"="); break; case 1: strcat(tot[9],"="); break; case 0: strcat(tot[10],"="); break; default: break; } } break; } else { printf("您的手大概抽筋,分數只能從 0~100\n"); } } } printf("\n=== 成績分布橫條圖 ===\n"); for(qtycnt=0;qtycnt<=10;qtycnt++) { printf("%s\n",tot[qtycnt]); strcpy(tot[qtycnt],tmt[qtycnt]); } } else { printf("輸入錯誤,請重新輸入!\n"); system("PAUSE"); } } return 0; }
以上"幾乎"是您要的解答,自己再修改一下吧,最好別用死當爭取同情,真的不會被當並不冤枉
不然拿到的文憑也是屬於別人的,相信沒人希望身體不適時看的醫生是靠別人畢業的,或是搭船
搭飛機搭高鐵時,設計或建造這些設備的工程師是靠別人畢業的,您說對吧
|