A Very Big Sum

Calculate and print the sum of the elements in an array, keeping in mind that some of those integers may be quite large.

Write a program to find the sum of big elements in the array

Example:

Input:  5,arr[]={1000000001,1000000002,1000000003,1000000004,1000000005}
Output: 5000000015

Approach

C++

#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n = 5;
    int i;

    long long int a[n] = {10000000011000000002100000000310000000041000000005};
    long long int sum = 0;

    for (i = 0i < ni++)
    {
        sum = sum + a[i];
    }
    cout << sum;
    return 0;
}


No comments:

Post a Comment