1+2+3+....+1000 Not Working?(Help C programming)

I’m trying to make program for
1+2+3+…+1000 using for loop in C language.I already wrote this but i don’t know why it’s not working :frowning:
my code is here-

#include <stdio.h>

int main()
{
    int i, n, sum;

    printf("Please enter the value of n: ");
    scanf("%d", &n);

    for(i = 1, sum = 0; i <= n; i++){
        sum = sum + 1;
    }

    printf("Summation is %d\n", sum);

    return 0;
}

Please anyone help me,I will grateful to you :heart:
Thank you~

You are doing

sum = sum+1; 

This adds 1 to sum n times.

What you want is

sum = sum+i 
1 Like

Thank you so much :heart::heart::heart:

As some concluding notes.

This is mostly a question of aestatetics, but it can make code more readable to adopt compound assignment.

sum = sum+i
can be shortened to

sum += i