C Program to Print Odd Numbers Between 1 to n using For Loop

Write a Program to Print Odd Numbers Between 1 to n using For Loop

// C Program to Print Odd Numbers Between 1 to n

#include <stdio.h>

int main()
{
	int n, i;

	printf("Enter the number :--> ");
	scanf("%d",&n);

	printf("\nOdd Numbers Between 1 to %d :--> ", n);

	for(i = 1; i<=n; i++)
	{
		if(i % 2 != 0)
		{
			printf("%d ",i);
		}
	}
	return 0;
}

Output:

Enter the number :--> 10

Odd Numbers Between 1 to 10 :--> 1 3 5 7 9

≪ Previous | Next ≫