C Program to print the sum of n odd numbers using do 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;
    do
    {
        if(i%2 != 0)
        {
            sum = sum + i;            
        }
	i++;
    }while (i <= n);
    printf("Sum of all odd numbers from 1 to %d is: %d", n, sum);
}

Output

$ gcc sum-of-n-odd-numbers-using-do-while.c 
$ ./a.out
Enter the value of n 
5
Sum of all odd numbers from 1 to 5 is: 9