

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C++ Program to add few large numbers
Suppose we have an array nums of some large numbers. The large numbers are in range (-2^31 to 2^31 - 1). We have to find the sum of these numbers.
So, if the input is like nums = [5000000003, 3000000005, 8000000007, 2000000009, 7000000011], then the output will be 25000000035.
To solve this, we will follow these steps −
- x := 0
- for initialize i := 0, when i < size of nums, update (increase i by 1), do −
- x := x + nums[i]
- return x
Example
Let us see the following implementation to get better understanding
#include <iostream> #include <vector> using namespace std; long long int solve(vector<long long int> nums){ long long int x = 0; for(int i=0; i<nums.size(); i++){ x = x + nums[i]; } return x; } int main(){ vector<long long int> nums = {5000000003, 3000000005, 8000000007, 2000000009, 7000000011}; cout << solve(nums); }
Input
{5000000003, 3000000005, 8000000007, 2000000009, 7000000011}
Output
25000000035
- Related Questions & Answers
- C++ Program to Find Factorial of Large Numbers
- How to add/subtract large numbers using Python?
- C++ Program to Add Two Numbers
- Add grouping specifiers for large numbers in Java
- Large Fibonacci Numbers in C#
- Handling large numbers in C++?
- Divisible by 37 for large numbers in C++ Program
- Program to Add Two Complex Numbers in C
- Sum of two large numbers in C++
- Java Program to Add Two Numbers
- Python program to add two numbers
- Write a program to add two complex numbers using C
- Program to find product of few numbers whose sum is given in Python
- Multiply Large Numbers represented as Strings in C++
- 8085 program to add 2-BCD numbers
Advertisements