C Program to print ODD numbers till N

Get input n and print odd numbers till n.

Sample Input 1:


Sample Output 1:

1 3 5 7

Flow Chart Design

C Program to print ODD numbers till N Flow Chart

Program or Solution

int main()
	int n,i;
	printf("Enter a number:");
	printf("odd numbers till %d:\n",n);
		printf("%d ",i);
	return 0;

Program Explanation

Instruction(s) inside the for block{} are executed repeatedly till the second expression (i<=n) is true.

Here i is initialized to 1 and incremented by 2 for each iteration, instructions inside the for block are executed unless i becomes greater than n.

so value of i will be printed like 1 3 5 .... (n-1) or n using printf statement.