I. Questions and codes
/ * file name: Ex1-1.cpp * Creator: Wang Yongbin * Completion Date: May 7, 2016 * Version number: v1.0 * Description of the task and solution method part: Substituting a set of numbers into an array, then using The parity separates it. * Input Description: Enter 10 numbers * Problem Description: No * program output: "Output 10 numbers and Separation results" * Problem analysis: slightly * algorithm design: First generation re-separation * * include <iostream.h>void main () {
int const n=10; int a[n],b[n],c[n],i,j=0,k=0; for (i=0;i<10;i++) { cin>>a[i]; if (a[i]%2!=0) { b[j]=a[i]; j + +; } else { c[k]=a[i]; k++; } } cout<< "Odd Group" <<endl;for (i=0;i<j;i++) cout<<b[i]<< " <<endl;cout<<" even group "<<endl;for (i=0;i<k;i++) cout<<c[i]<<" "<<ENDL;}
Ii. Results of operation
Third, experience
The loop structure should be used well, otherwise the running result will be wrong.
Iv. Summary of Knowledge points
Arrays are applied to the loop structure to distinguish the order.
C + + experiment 5-array separation