标签:ini arc style 函数 images 作业 class reads ima
#include<stdio.h> #define N 100 void readscore(int score[],int n); double average(int grade[],int n); int maxindex(int grade[],int n); int minindex(int grade[],int n); int search(int num[],int n,int x); void bubblesort(int grade[],int n); void printscore(int grade[],int n); int main() { int score[N],n,max,min,m,num,x; double ave; printf("Please input the number of the students:\n"); scanf("%d",&n); readscore(score,n); ave=average(score,n); max=maxindex(score,n); min=minindex(score,n); printf("The average of the grade is %.2f,The maxindex is %d,The minindex is %d\n",ave,max,min); printf("Please input the grade of the student.\n"); scanf("%d",&x); m=search(score,n,x); printf("This students index is%d\n",m); bubblesort(score,n); printscore(score,n); return 0; } void readscore(int score[],int n) { int i; printf("Please input the score:\n"); for(i=0;i<n;i++) { scanf("%d",&score[i]); } } double average(int score[],int n) { int i; double sum; sum=0; for(i=0;i<n;i++) { sum+=score[i]; } return (double)sum/n; } int maxindex(int score[],int n) { int i,maxindex=0; for(i=1;i<n;i++) { if(score[i]>score[maxindex]) { maxindex=i; } } return maxindex; } int minindex(int score[],int n) { int i,minindex=0; for(i=1;i<n;i++) { if(score[i]<score[minindex]) { minindex=i; } } return minindex; } int search(int num[],int n,int x) { int i; for(i=0;i<n;i++) { if(num[i]==x) { return i; } } return -1; } void bubblesort(int score[],int n) { int i,j,t,flag; for(i=0;i<n-1;i++) { flag=0; for (j=0;j<n-1;j++) { if(score[j]>score[j+1]) { t=score[j]; score[j]=score[j+1]; score[j+1]=t; flag=1; } } if(flag==0) { break; } } } void printscore(int score[],int n) { int i; for(i=0;i<n;i++) { printf("%5d",score[i]); } printf("\n"); }
实验结果:
#include<stdio.h> #define N 100 int main() { int i,num[N]={0},a=0; for(i=0;i<N;i++) { num[i]=i+1; } for(i=0;i<N;i++) { if(num[i]%3==0||num[i]%7==0) { num[i]=0; } else { a++; printf("%5d\n",num[i]); } } printf("It remaid %d numbers",a); return 0; }
运行结果:
本次实验总结:
实验代码写完以后,一运行有很多小的错误,比如在用函数的时候,后面加了‘;’,for循环里用的‘,’而不是‘;’,
但是,对第一个代码的思路比较清楚,不混乱。
第二个代码一开始不知道怎么下手,虽然老师上课讲了,但是一点都没思路= =。但是看了同学的以后,就明白了...
标签:ini arc style 函数 images 作业 class reads ima
原文地址:http://www.cnblogs.com/jj4529926/p/6132293.html