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; }
以上"几乎"是您要的解答,自己再修改一下吧,最好别用死当争取同情,真的不会被当并不冤枉
不然拿到的文凭也是属于别人的,相信没人希望身体不适时看的医生是靠别人毕业的,或是搭船
搭飞机搭高铁时,设计或建造这些设备的工程师是靠别人毕业的,您说对吧
|