1068. Sum

Mar 14, 2012 at 5:50pm
I need to find the sum of all integer numbers lying between 1 and N inclusive and it seems that my program is wrong..

Input
The input consists of a single integer N that is not greater than 10000 by it's absolute value.
Output
Write a single integer number that is the sum of all integer numbers lying between 1 and N inclusive.

My program:
#include<iostream>
using namespace std;
int main()
{
int n,i,s;
cin>>n;
s=0;
for(i=1;i<=n;i++) s=s+i;
cout<<s;
return 0;
}

Mar 14, 2012 at 5:59pm
What makes you think it doesn't work?
Mar 14, 2012 at 6:48pm
Looks fine to me
Topic archived. No new replies allowed.