Search This Blog

Read Your Language

Writes a C++ Program to find out the sum of n numbers.

Writes a C++ Program to find out the sum of n numbers.


#include <iostream>
using namespace std;

int main()
{
    int n,i,sum=0;

    cout << "Enter a positive integer: ";
    cin >> n;

    for ( i = 1; i <= n;i++) 
{
        sum=sum+i;
    }

    cout << "Sum=" << sum;
    return 0;

}


OUTPUT:
Enter a positive integers:
6
Sum=21

No comments:

Contact Form

Name

Email *

Message *

Followers