I. Questions and codes
file name: array separation * AS By: Liu Jia Material * completion date: May 10, 2016 * Version number: v1.0 * Description of Task and solution Method section: Using Arrays and for language * Input Description: Enter 10 integers * problem description: Separate odd and even * program output: Even Group C is : 2 4 6 8 0 Odd Group B is: 1 3 5 7 9* Problem analysis: Using array * Algorithm design: For statement if statement #include <iostream.h> void Main () {const int n=10; int a[n],c[n],b[n],i,j=0,k=0; cout<< "Please enter 10 number:" <<endl; for (i=0;i<n;i++) {cin>>a[i]; if (a[i]%2==0) {c[j]=a[i]; j + +; } else {b[k]=a[i]; k++; }} cout<< "Even Group C is:"; for (j=0;j<n-k;j++) {cout<<c[j]<< ""; cout<<endl; } cout<< "Odd Group B is:"; for (k=0;k<n-j;k++) {cout<<b[k]<< ""; cout<<endl; } }
Two. Running results
Three. Experience:
Actually not very will do this, fortunately, today the teacher explained a bit, on the copy down, a back on the write up, afraid to forget
Four. Summary of Knowledge points:
Utilize the FOR statement, if statement, to utilize the array
C + + Fifth experiment--array separation