Sum of Numbers in an Array in C++

Download
Download is available until [expire_date]
  • Version
  • Download 19
  • File Size 1.31 KB
  • File Count 1
  • Create Date May 9, 2016
  • Last Updated May 9, 2016

Sum of Numbers in an Array in C++

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;
}
, , , , , ,

Post navigation

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.