To add the odd numbers in C


Levels of difficulty: / perform operation:

C program to add the odd numbers within a given number.

C Program

#include <stdio.h>
#include <conio.h>
void main()
{
	int i,n;
	unsigned long sum=0;
	clrscr();
	printf("\nENTER A NUMBER: ");
	scanf("%d",&n);
	for(i=1;i<=n;i+=2)
	{
		sum=sum+i;
	}
	printf("\nSUM OF THE ODD NUMBERS BETWEEN 1 TO %d IS %lu",n,sum);
	getch();
}


Output