Thursday, November 16, 2017

1049 - Sum COJ Problem Solution

http://coj.uci.cu/24h/problem.xhtml?pid=1049

In C++..................

#include<iostream>
#include<cstdio>

//Nayeem Shahriar Joy, Applied Physics And Electronic Engineering,University of Rajshahi.

using namespace std;

int main()

{
    int N,sum=0;

    cin>>N;
    if(N<=0)
    {
        for(int i=N;i<=1;i++)
        {
            sum=sum+i;
        }
    }
    else

    {
        for(int i=1;i<=N;i++)
        {
            sum=sum+i;
        }
    }
    cout<<sum<<endl;
    return 0;
}

No comments:

Post a Comment