First, the contents of the experiment
1, the experimental requirements:
1, the definition function realization: Enters several student's achievement (the input number or the negative end can be), the average score, the highest score and the lowest score, and points out the highest score and the lowest score student (gives the subscript can), enters a result, explains is the first several student's achievement, finally according to the result from high to low the output. (Minimum of seven functions.) Input function, mean function, max subscript function, minimum value subscript function, lookup function, sort function, output function)
Code:
#include <stdio.h>#defineN 100voidShuru (intScore[],intn);DoubleAverageintScore[],intn);intMaxindex (intScore[],intNintmax[]);intMinindex (intScore[],intNintmin[]);intFindIndex (intAintScore[],intNintfind[]);voidPaixu (intScore[],intn);voidShuchu (intScore[],intn);intMain () {inti,score[n]={0},n,max[n]={0},min[n]={0},f,find[n]={0}; printf ("Please enter the number of students \ n"); scanf ("%d",&N); Shuru (Score,n); printf ("average divided into%.2lf\n", average (score,n)); printf ("the students with the highest scores are:"); I=Maxindex (Score,n,max); Shuchu (Max,i); printf ("the students with the lowest grades are:"); I=Minindex (score,n,min); Shuchu (Min,i); printf ("Please enter the score you want to find:"); scanf ("%d",&f); if(FindIndex (f,score,n,find)) {i=FindIndex (F,score,n,find); printf ("The students of this grade are: \ n"); Shuchu (Find,i); } Else{printf ("The score you are looking for does not exist. \ n"); } printf ("arrange your grades from small to large: \ n"); Paixu (Score,n); Shuchu (Score,n); return 0;} voidShuru (intScore[],intN) { inti; for(i=0; i<n;i++) {printf ("Please enter the score of%d students: \ n", i+1); scanf ("%d",&Score[i]); }}DoubleAverageintScore[],intN) { inti,sum=0; for(i=0; i<n;i++) {sum=sum+Score[i]; } return(Double) sum/N;}intMaxindex (intScore[],intNintmax[]) { inti,max,index=0; Max=score[0]; for(i=0; i<n;i++) { if(score[i]==Max) {Max[index++]=i; } Else if(score[i]>Max) {Max=Score[i]; Index=0; Max[index++]=i; } } returnindex;}intMinindex (intScore[],intNintmin[]) { inti,min,index=0; Min=score[0]; for(i=0; i<n;i++) { if(score[i]==Min) {Min[index++]=i; } Else if(score[i]<Min) {Min=Score[i]; Index=0; Min[index++]=i; } } returnindex;}intFindIndex (intAintScore[],intNintfind[]) { inti,index=0, flag=0; for(i=0; i<n;i++) { if(a==Score[i]) {Find[index++]=i; Flag=1; } } if(flag==0) return 0; Else returnindex;}voidPaixu (intScore[],intN) { intI,j,temp,flag; for(i=0; i<n-1; i++) {flag=0; for(j=0; j<n-1-i;j++) { if(score[j]>score[j+1]) {temp=Score[j]; SCORE[J]=score[j+1]; Score[j+1]=temp; Flag=1; } } if(flag==0) Break; }}voidShuchu (intScore[],intN) { inti; for(i=0; i<n;i++) {printf ("%d\n", Score[i]); }}
Program Run Result:
2, define the length of the integer array of 100, the array element is assigned the initial value of ... 100, delete all values that are 3 or 7 times times, and the number of remaining digits in the output array and each number.
Code:
#include <stdio.h>#defineN 100intMain () {inta[n],i,b=0; for(i=0;i< -; i++) {A[i]=i+1; if(a[i]%3==0|| a[i]%7==0) {A[i]=0; b++; } if(a[i]!=0) {printf ("%d\t", A[i]); }} printf ("number of%d left \ n", --b); return 0;}
Program Run Result:
Second, the experiment summary (the problem encountered in the experiment and the solution method)
1, the function name should be the same, pay attention to the use.
2. Notice the cross-border problem of the array.
3. The return value should be placed outside the loop.
4, bubble sorting method of thinking is: the adjacent two numbers to compare, the small tune to the front!
5, pay attention to distinguish the data type, when necessary to make mandatory data conversion
Nineth Time Assignment