I got a problem with my program that should sum the numbers from 1 to 70000 (1+2+3+4+...+69999+70000). My program can sum the numbers up to 65535 without a problem, but for any summing above 65535, the result shows negative numbers, which is wrong. Can anyone explain to me why my program can not sum numbers above 65535?
this is my code :
#include <stdio.h>
void sum(int *s)
{
*s=0;
int i=1;
int n=70000;
while(i<=n)
{
*s+=i;
i++;
}
}
main()
{
int s;
sum(&s);
printf("Suma prirodnih brojeva od 1 do 70000 je: %d\n",s);
}