Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
Write a program that computes the sum of the first ten positive integers, 1 + 2 + ... + 10.?
C
C plus plus
3 Answers
- _ObjectLv 67 years agoFavorite Answer
Gauss formula:
#include <iostream>
int main (int, char **) { std:: cout << ((10 * 10 + 10 * 1) / 2); return 0; }
- Anonymous7 years ago
C++
#include <iostream>
using namespace std;
int main() {
int n = 10;
printf("%d", n * (n+1) / 2);
}
- 7 years ago
#include <iostream>
using namespace std;
int main()
{
int sum(0), x(10);
sum= x * (x+1) / 2;
cout<<"Sum is "<<sum;
system("pause>0");
return 0;
}
-------OR---------------
#include <iostream>
using namespace std;
int main()
{
int sum=0;
for(int i=1;i<11;i++)
{sum+=i;
}
cout<<"Sum is "<<sum;
system("pause>0");
return 0;
}