C + + experiment 5 Project 1: Array separation

Source: Internet
Author: User

Questions and codes


/* for    : Liang  * Completion Date: May 8, 2016  * Version number: v1.0  * Description of the task and solution method part:  * Input Description: No  * Problem Description: Enter 10 numbers from the keyboard in the array A, The odd number in the array is placed in array B, and the even number is placed in the array C and then output separately. * Program output: 10 number of odd and even * problem analysis:  * Algorithm Design: *  /#include <iostream>using namespace Std;int main () {int a[10],b[10],c[ 10],j=0,k=0;cout<< "Enter 10 integers, separated by spaces" <<endl;for (int i=0;i<10;i++) cin>>a[i];for (i=0;i<10;i+ +) {if (a[i]%2!=0) b[j]=a[i],j++;elsec[k]=a[i],k++;} cout<< "Odd number:" <<endl;for (i=0;i<j;i++) cout<<b[i]<< "";cout<<endl;cout<< "even have "<<endl;for (i=0;i<k;i++) cout<<c[i]<<" "; return 0;

Run results


Experience: Changed for a long time, the operation has appeared random number, and then slowly try to finally fix


C + + experiment 5 Project 1: 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.