C + + experiment 5: Summation

Source: Internet
Author: User
One. Questions and codes
/  * file name: 111111.cpp  *    Creator: Can andi remember * completion date: 2016  month 8th  * Version number: v1.0  * Description of the task and solution Method Section: * Input Description: None  * Problem Description: Enter 10 numbers from the keyboard into the array A, the sum of the positive and negative numbers in the a array. * Program output: "The sum of positive and negative numbers in a array"  * Problem analysis: slightly * algorithm design: Slightly */    #include <iostream>    using namespace std;    void Main ()    {double X=0,y=0;int a[10],n;cout<< "Please enter any 10 numbers:"; for (n=0;n<10;n++) {cin>>a[n];if (A[n] >0) x+=a[n];elsey+=a[n];}  cout<< "Positive sum is:" <<x<<endl;cout<< "negative sum is:" <<Y<<ENDL;}

Two. Run results


Three. Experience

The program of the array is difficult to understand, after the class to write more about the array of programs to achieve proficiency in the effect.

Four. Summary of Knowledge points

When writing array problems, n or I are generally good starting from 0, and when grouping sums, remember that the condition is clear to avoid affecting the whole program's operation because of the condition error.


C + + experiment 5: Summation

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.