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.

Write a program that computes the sum of the first ten positive integers, 1 + 2 + ... + 10.?

Update:

C

Update 2:

C plus plus

3 Answers

Relevance
  • 7 years ago
    Favorite Answer

    Gauss formula:

    #include <iostream>

    int main (int, char **) { std:: cout << ((10 * 10 + 10 * 1) / 2); return 0; }

  • Anonymous
    7 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;

    }

Still have questions? Get your answers by asking now.