项目二
#include <iostream> using namespace std; int main() { int A[10],B[10],C[10],i,j=0,k=0; cout<<"请输入10个数:"<<endl; for(i=0;i<10;i++) { cin>>A[i]; } for(i=0;i<10;i++) { for(j=i+1;j<10;j++) { if(A[i]==A[j]) { B[i]=A[i]; B[j]=A[j]; } } } cout<<endl<<"其中不重复的数字有"; for(i=0;i<10;i++) { if(A[i]==B[i]) continue; C[k]=A[i]; cout<<C[k]<<", "; k++; } return 0; }项目三
#include <iostream> #include<cmath> using namespace std; int main() { double score[10],aver=0,MAX,MIN; int a[10],b[10],i,N,count1=0,count2=0,k=0,j=0; cout<<"请输入小组人数:"; cin>>N; cout<<"请输入成绩:"; for(i=0;i<N;i++) { cin>>score[i]; if(score[i]<0 || score[i]>100) { cout<<"成绩范围是0~100,请重新输入:"; i--; } } aver=aver+score[0]; MAX=MIN=score[0]; for(i=1;i<N;i++) { if(score[i] > MAX) MAX=score[i]; else if(score[i] < MIN) MIN=score[i]; aver=aver+score[i]; } aver=aver / N; for(i=0;i<N;i++) { if(score[i]==MAX) { count1++; a[k]=i; k++; } else if(score[i]==MIN) { count2++; b[j]=i; j++; } } cout<<"该小组的最高成绩是"<<MAX<<",最低成绩是"<<MIN<<",平均成绩是"<<aver<<endl; cout<<"最高成绩和最低成绩的人数分别是"<<count1<<" "<<count2<<endl; cout<<i+1<<"考得最高成绩同学学号:"; for(i=0;i<k;i++) cout<<a[i]<<" "; cout<<endl<<i+1<<"考得最低成绩同学学号:"; for(i=0;i<j;i++) cout<<b[i]<<" "; cout<<endl; return 0; }
#include <iostream> #include<cstdio> using namespace std; int main() { char str[50]; int i=0,n=0,m=0,j=0; cout<<"输入字符串:"; gets(str); while(str[i]!='\0') { if(str[i]>='0'&&str[i]<='9') n++; else if((str[i]>='a'&&str[i]<='z')||(str[i]>='A'&&str[i]<='Z')) m++; else j++; i++; } cout<<"其中的数字个数是: "<<n<<endl; cout<<"其中的字母个数是: "<<m<<endl; cout<<"其中的其他字符个数是: "<<j<<endl; return 0; }