C + + 5th time on-machine experiment-array separation

Source: Internet
Author: User

First, Questions and Codes

/** file name: array separation. cpp*    :  Cong * Completion date:  May 8 * Version number: v1.0* Description of the task and solution method part: * Input Description: Enter 10 integers * Problem Description: Slightly * program output: Output 1 respectively 0 odd and even numbers in the number; * Problem analysis: Isolating array output, using variable for different use * algorithm design: For  statement and array combination, and if Else statement to judge */#include <iostream>using namespace std; int main () {int a[10],b[10],c[10],i,j=0,k=0; cout<< "Please enter an integer of 10 array A:" <<endl; for (i=0;i<10;i++) {     cout << "a[" <<i<< "]=";      cin>>a[i]; } for (i=0;i<10;i++)     {        if (a[i]%2!=0)         {          j + +;          B[j]=a[i];         }        else         {          k++;          C[k]=a[i];         }     } cout<< "Array B:"; for (i=1;i<=j;i++)        cout<< "b[" <<i<< "]=" <<b[i]<< "\ T";        cout<< "\ n" << "array C:";      for (i=1;i<=k;i++)        cout<< "c[" <<i<< "]=" <<c[i]<< "\ T"; return 0;}
Ii. Results of operation

Third, experience

The first attempt to use the array to write a program, wrote a long time, the emergence of a variety of problems, 1.1 points with cout output debugging program, 1.1 points to solve the problem, finally understand how to better operate, this program is a little complicated, but I do not want to change, leave a memorial it.

Iv. Summary of Knowledge points

Array input and output should be organized, not using the unknown variable output, pay special attention to the array of each number corresponding to the location.

C + + 5th time on-machine experiment-array separation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.