1. 作业题目:比较大小
代码:
#include<stdio.h> int main() { int i,j,a[10],index,n,temp; printf("Enter n:"); scanf("%d",&n); for(i=0;i<n;i++) scanf("%d",&a[i]); for(i=0;i<n-1;i++){ index=i; for(j=i+1;j<n;j++) if(a[j]<a[i]) index=j; temp=a[index]; a[index]=a[i]; a[i]=temp; } printf("After sorted:"); for(i=0;i<n;i++){ printf("%5d",a[i]); } printf(" "); return 0; }
测试截图:
2.作业题目:高速公路超速处罚
代码:
#include<stdio.h> int main() { int number,i; printf("高速公路本车道限速:"); scanf("%4d",&number); printf(" "); printf("车速:"); scanf("%4d",&i); printf(" "); if(i<1.1*number){ printf("正常! "); } else if(i>1.1*number && i<1.5*number){ printf("200元罚款! "); } else{ printf("吊销驾驶证! "); } printf(" "); return 0; }
测试截图:
4.作业题目:统计学生成绩
代码:
#include<stdio.h> int main(void) { int i,n; int A,B,C,D,E; A=B=C=D=E=0; double grade,total=0; printf("输入学生个数n:"); scanf("%d",&n); double total_A = 0; double total_B = 0; double total_C = 0; double total_D = 0; double total_E = 0; for(i=1;i<=n;i++){ printf("输入学生个数#%d:",i); scanf("%lf",&grade); total = total + grade; int switch_grade = grade / 10; switch(switch_grade){ case 10: case 9: { printf("90~100 "); A++; total_A = total_A + grade; break; } case 8: { printf("80~89 "); B++; total_B = total_B + grade; break; } case 7: { printf("70~79 "); C++; total_C = total_C + grade; break; } case 6: { printf("60~69 "); D++; total_D = total_D + grade; break; } default: { printf("ERROR "); E++; total_E = total_E + grade; break; } } } printf("所有学生的总成绩=%.2f ",total); printf("每个等级的人数: A-%d B-%d C-%d D-%d E-%d ",A,B,C,D,E); return 0; }
测试截图:
总结:
这一次有不会的,还需多加练习。
以前学过的还是要好好复习啊,切记/(ㄒoㄒ)/~~