# Forum

25.04.2010   # 1
my SumOfConsecutiveNumbers problem
i missed today's contest but i want to ask something.
At the SumOfConsecutiveNumbers (500) problem my DEV c++ compiler doesn't want to run the program...

it compiles but it doesn't run the program... i think that the code is OK
Can someone tell me what am i doing wrong?

#include <iostream>
using namespace std;

int suma(int n,int m)
{if(n==m)return m;
return n+suma(n++,m);}

class SumOfConsecutiveNumbers
{
public:
int largestN(int S)
{
int n,m; int N=0;
for(n=1;n<=S;n++)
{
for(m=n;m<=S;m++)
{
if((suma(n,m)==S)&&(N<(m-n+1)))
N=(m-n+1);
}
}
return N;
}
};

int main()
{int n;
SumOfConsecutiveNumbers klasa;
cout<<"Vnesete broj:";
cin>>n;
cout<<"Dobieniot broj e "<<klasa.largestN(n);
system("pause");}
25.04.2010   # 2
it is OK now... i fixed it... one For cycle instead of recursion

#include <iostream>
using namespace std;

int suma(int n,int m)
{int zbir=0;
for(;n<=m;n++)
zbir+=n;
return zbir;}

class SumOfConsecutiveNumbers
{
public:
int largestN(int S)
{
int n,m; int N=0;
for(n=1;n<=S;n++)
{
for(m=n;m<=S;m++)
{
if((suma(n,m)==S)&&(N<(m-n+1)))
N=(m-n+1);
}
}
return N;
}
};

int main()
{int n;
SumOfConsecutiveNumbers klasa;
cout<<"Vnesete broj:";
cin>>n;
cout<<"Dobieniot broj e "<<klasa.largestN(n);
system("pause");}