hi,
well this is my first post on this great forum, hope to be a good boy :)
i m writing a programm that adds numbers from 0 to any numer entered by the user .
for Example :
- if the user enter 4, the sum will be 10 = 0+1+2+3+4.
- if 10 --> the sum is : 1+2+3+4...+10 = 64 .
i make the code like that :
#include <stdio.h>
#include <stdlib.h>
int main()
{
int number;
int sum;
int i;
printf("please enter the end number : \n" );
scanf("%i", &number);
for ( i = 0; i <= number; i++ ) {
sum += i;
}
printf("the sum is : %i\n", sum);
return 0;
}
the result :
the sum is : 2293586 when i enter 4 :-/ i don t know why .
any ideas how to make this work
Thanks.