write a program in c++ to calculate the sum of three number for 3 times using loop
Answers
Answer:
#include <iostream>
int main()
{
int v[] = { 1, 2, 3 };
std::cout << v[0] + v[1] + v[2] << std::endl;
}
#include <algorithm>
#include <iostream>
#include <numeric>
int main()
{
int v[] = { 1, 2, 3 };
std::cout << std::accumulate(std::begin(v), std::end(v), 0, std::plus<>()) << std::endl;
return 0;
}
int main()
{
int v[] = { 1, 2, 3 };
std::cout << std::accumulate(std::begin(v), std::end(v), 0, [](int tot, int i) { return tot + i; }) << std::endl;
return 0;
}
#include <boost/range/numeric.hpp>
int main()
{
int v[] = { 1, 2, 3 };
std::cout << boost::accumulate(v, 0);
}
#include <vector>
int main()
{
std::vector<int> v = { 1, 2, 3 };
int sum = 0;
std::for_each(v.begin(), v.end(), [&](int& i) { sum += i; });
std::cout << sum << std::endl;
return 0;
}
281 views
View upvotes
1
Related Questions (More Answers Below)
How do I write a C++ program to print a sum of two numbers?
1,727 Views
How can I write a C program that will print prime numbers between 100 to 500?
73,333 Views
How can I write a program to find the sum and average of three numbers?
3,419 Views
How do I write a C++ program to find the largest number among three numbers using (if Statements)?
5,682 Views
How do I write a program to accept three numbers?
1,606 Views

Sayantan Ghosh, Resident Alien, Non Resident Indian
Answered 1 year ago
int a,b,c;
cout << "Please enter an integer value for variable a ";
cin >> a;
cout << "Please enter an integer value for variable b ";
cin >> b;
cout << "Please enter an integer value for variable c ";
cin >> c;
cout <<a<<" + "<<b<<" + "<<c" = "<<a+b+c;
165 views
View upvotes
1
Sponsored by Jigsaw Academy
Accelerate your career with Postgraduate Diploma In Data Science.
A comprehensive program that offers a perfect blend of data science & emerging technologies.
Apply Now
Related Answers
Related Answer

Narayan Menariya, Telecom Software Engineer at Tayana Software Solutions
Answered 2 years ago · Author has 354 answers and 1M answer views
How can I write a C program that will print prime numbers between 100 to 500?
Here first i am writing an algorithm so that later it can be converted into program no matter whether its C programming , C++ Programming or Java programming, Later we will write C Program using the same algorithm.
Algorithm:
Step 1: Read number X in any integer variable, let that variable is “NumX”.
Step 2: Read second number y in another integer variable let say “NumY”.
Step 3: Finding prime number between NumX and NumY: In order to find all the prime number present between two number NumX and NumY , we need to run a nested loop along with if statement as follows:
Step 3.1) Run a loop from Ind
Continue Reading
16
1
Related Answer