标签:
项目一、数组分离
#include<iostream> using namespace std; int main() { const int N=5; double score[N],max,min,aver,i; cout<<"输入小组成绩:"; for(i=0;i<N;i++) { cin>>score[i]; } max=min=aver=score[0]; for( i=1;i<N;i++) { aver+=score[i]; if(score[i]>max) max=score[i]; else if(score[i]<min) min=score[i]; } aver=aver/10.0; cout<<max<<" "<<min<<" "<<aver; return 0; }
项目3:成绩
<pre name="code" class="cpp">#include<iostream> using namespace std; int main() { const int N=10; int score[N],a[N],b[N],max,min,i,m=0,n=0,j=1,k=1; double aver; cout<<"输入小组成绩(0到100):"; for(i=0;i<N;i++) { cin>>score[i]; } max=min=aver=score[0]; for( i=1;i<N;i++) { aver+=score[i]; if(score[i]>max) max=score[i]; else if(score[i]<min) min=score[i]; } aver=aver/10.0; cout<<"max="<<max<<endl; cout<<"min="<<min<<endl; cout<<"aver="<<aver<<endl; for( i=0;i<=N;i++) { if(score[i]==max) {m++; cout<<i+1<<" ";} }cout<<"号同学成绩最高"<<endl; for( i=0;i<=N;i++) { if(score[i]==min) {n++; cout<<i+1<<" ";} }cout<<"号同学成绩最低"<<endl; cout<<endl; cout<<"考得最高成绩的人数为:"<<m<<"人"<<endl; cout<<"考的最低成绩的人数为:"<<n<<"人"<<endl; return 0; }
项目4:字符串
<pre name="code" class="cpp">#include<iostream> using namespace std; int main() { char str[50]; int i=0,x=0,y=0,z=0; cout<<"输入字符串:"; gets(str); while(str[i]!='\0') { if(str[i]>='0'&&str[i]<='9') x++; else if((str[i]>='a'&&str[i]<='z')||(str[i]>='A'&&str[i]<='Z')) y++; else {z++;} i++; } cout<<"其中的数字个数是: "<<x<<"个"<<endl; cout<<"其中字母的个数是:"<<y<<"个"<<endl; cout<<"其他字符的个数是:"<<z<<"个"<<endl; return 0; }
标签:
原文地址:http://blog.csdn.net/xuchongminproject/article/details/51344244