13.c++ program to calculate sum of natural numbers

//  C++ program to calculate sum of natural numbers

INPUT:

#include<iostream>

using namespace std;

int main()

{

    int x,y=0,i;

    cout<<"Enter a positive integer : ";

    cin>>x;

    for(i=1;i<=x;i++)

        {

            y=y+i;

        }

    cout<<"\n Sum = "<<y<<endl;

    return 0;

}

OUTPUT:





 

Comments

Popular posts from this blog

8.c++ program to check whether the number is even or odd

1.c++ program to find the total marks and average of three subjects

4.c++ program to compute quotient and remainder