C Program to print odd numbers between 1 to n using While loop

Write C Program to print odd numbers between 1 to n using While loop

/WAP to print odd numbers between 1 to n

#include <stdio.h>

int main()
{
	int n;

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

	int i = 1;

	printf("The odd numbers are :--> ");

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

	return 0;

}

Output:

Enter the number :--> 21
The odd numbers are :--> 1 3 5 7 9 11 13 15 17 19

≪ Previous | Next ≫