I. Questions and codes
/* File name: Fourth Experiment * by: Shaki * Completion Date: May 5, 2016 * Version number: v1.0 * Description of the task and solution Method Section: Item 1: Array separation * Input Description: Slightly c8/>* problem Description: Slightly * Program output: Enter 10 numbers from the keyboard in the array A, put the odd number in the array B, the even number is placed in the array C and output separately. * Problem Analysis: slightly * algorithm design: Array */ #include <iostream.h> void Main () {const int n=10;int a[n],b[n],c[n],i,j=0,k= 0,d,e,f;cout<< "Please enter any of the 10 real numbers into the array A:" <<endl;for (i=0;i<10;i++) {cin>>a[i];d =a[i]%2;if (d==1) {b[j]= a[i];j++;} else if (d==0) {c[k]=a[i];k++;} } cout<< "Array A:"; for (i=0;i<10;i++) {cout<<a[i]<< "";} cout<<endl;cout<< "Array B:"; for (e=0;e<j;e++) {cout<<b[e]<< "";} cout<<endl;cout<< "Array C:"; for (f=0;f<k;f++) {cout<<c[f]<< "";} Cout<<endl;}
two, running results
Third, Experience:
At first I want to use the For statement to do, and later found it difficult, so instead of using the For statement plus if to do is simpler.
Iv. Summary of Knowledge points:
For statement. Array.
Experiment: C + + experiment 5-Item 1