C Program to find the sum of first n odd numbers using for loop

Program

#include<stdio.h>
void main()
{
	int n, i, odd_sum;
	odd_sum = 0;
	printf("Enter the value of n:\t");
	scanf("%d", &n);
	for(i = 1; i <= n; i++)
	{
		if((i %2) != 0)
		{
			odd_sum += i;
		}
	}
	printf("Sum of odd series from 1 to %d is %d\n", n, odd_sum);
}

Output

Enter the value of n:	15
Sum of odd series from 1 to 15 is 64