First, the results
#include <iostream.h>void main () {Double Ave; int score[10],i,max,min,sum=0,a=0,b=0; cout<< "Please input the results of group students" <<endl; for (i=0;i<10;i++) cin>>score[i]; MAX=SCORE[0]; for (i=1;i<9;i++) if (Max<score[i]) max=score[i];for (i=1;i<9;i++) if (Max==score[i]) a++; {min=score[0]; for (i=1;i<10;i++) sum=sum+score[i]; if (Min<score[i]) min=score[i]; for (i=1;i<10;i++) if (score[i]==min) b++; ave=sum/10.0; } cout<< "This group has the highest score of" <<max<< "\ n" << "total" <<a<< "person" << "study number" <<a<< Endl cout<< "Minimum score for this group is" <<min<< "\ n" << "total" <<b<< "person" << "study number" <<b<<endl ; cout<< "Average score" <<ave<<endl; }
Two, string
#include <iostream> #include <cstdio> using namespace std; int main () { char a[50]; int i=0,a=0,b=0,c=0; cout<< "Please enter string" <<endl; Gets (a); while (a[i]!= ') { if (a[i]>= ' 0 ' &&a[i]<= ' 9 ') a++; else if ((a[i]>= ' a ' &&a[i]<= ' z ') | | (a[i]>= ' A ' &&a[i]<= ' Z ')) b++; else C + +; i++; } cout<< "Number of numbers is:" <<a<<endl; cout<< "Number of letters:" <<b<<endl; cout<< "Number of other characters:" <<c<<endl; return 0; }
Three, array separation
#include <iostream.h> void Main () { int a[10],b[10]={0},c[10]={0},i,j,k;cout<< "Please enter 10 numbers" <<endl; for (i=0;i<10;i++) cin>>a[i]; for (i=0,j=0,k=0;i<10;i++) { if (a[i]%2) b[j++]=a[i]; else c[k++]=a[i]; } for (i=0;i<j;i++) cout<< "Odd is" <<b[i]<< ' \ t '; cout<<endl; for (i=0;i<k;i++) cout<< "Even is" <<c[i]<< ' \ t '; cout<<endl; }
C + + Job five