C Program to print the sum of n even numbers using while

Program

#include <stdio.h>
void main()
{
    int i, n;
    int sum = 0;
    printf("Enter the value of n \n");
    scanf("%d", &n);
    i = 1;
    while (i <= n)
    {
        if(i%2 == 0)
        {
            sum = sum + i;            
        }
	i++;
    }
    printf("Sum of all even numbers from 1 to %d is: %d", n, sum);
}

Output

$ gcc sum-of-n-even-numbers-using-while.c 
$ ./a.out
Enter the value of n 
50
Sum of all even numbers from 1 to 50 is: 650