Sum of Numbers in an Array in C++

Sum of Numbers in an Array in C++

Version
Download 8
Total Views 0
Stock
File Size 1.31 KB
File Type zip
Create Date May 9, 2016
Last Updated May 9, 2016
Download

Sum of Numbers in an Array in C++

A sample program in c++ that will compute the sum of numbers in an array. The program will compute and display the sum of 5 numbers in an array. The program uses for loop to compute the sum and stops the loop when the condition is met.

Source code:

#include < iostream >

using namespace std;

int main()
{
    int numarray[5]={5,4,56,6,4};
    int sum=0;

    for (int x=0;x<5;x++)
    {
        sum+=numarray[x];
    }
    cout << "the sum of 5 numbers = " << sum<< endl;
    return 0;
}

Comments

comments

Leave a Reply

Your email address will not be published. Required fields are marked *

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.