Experiment: C + + experiment 5-Item 1

Source: Internet
Author: User

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

Related Article

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.