I. Questions and codes
/** file Name: array separation * Creator: * Completion date: 5 months 8 Days * Version number: v1.0* Description of task and solution method part: Use an array and a for language * to enter a description:
input 10 Integers * problem Description: Odd number and even * program output: Even the Group A is: 12 24 36 78 Array B is: 13 5 67 89 9 19* Problem analysis: using array * algorithm design: For statement if statement */ #include <iostream>using namespace Std;int 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 A is:"; for (j=0;j<n-k;j++) { cout<<c[j]<< ""; } cout<< "Odd Group B is:"; for (k=0;k<n-j;k++) { cout<<b[k]<< ""; } return 0;}
Ii. Results of operation
Third, experience
Pay attention to the range of loops when using the For statement.
Iv. Summary of Knowledge points
The use of arrays makes input data simple and easier to read.
C + + 5th experiment-Array separation