#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
int i,j;
int sum1=0,sum2=0;
int n;
for(n=100;n<1000;n++) {
for(i=n-1;i>0;i--)
sum1 +=i;
for(j=n+1;sum1>sum2;j++)
sum2+=j;
if(sum1==sum2)
printf(" n may be %d\n\n ",n);
}
system("PAUSE");
return 0;
}
What about "m"? Are there any restrictions on "m"?
If the goal is to find an "n" such that the sum from 1 to n-1 is equal to the sum (n+1)+(n+2)+...+m, for some m >= n + 1, then your code is correct except for one problem: you should be setting sum1 and sum2 each back to zero at the beginning of the main loop.
OP, please don't delete your posts. Now no-one else can benefit from the help in this thread.
I don't think anyone gave you a full solution, so I don't know what you are afraid of. Surely your lecturer doesn't mind you asking for a hint? And if he/she does then you should probably have gone to him/her in the first place rather than breaking his/her rules and posting here. Just saying ^^