Question #343963

  1. Input a positive integer. This will serve as the starting point of the loop.
  2. Using a while() loop, print out all the odd numbers starting from the inputted integer, until 0. The outputted numbers must all be separated by line.
  3. Also remember that since the loop goes to descending order, a decrement variable shall be created and decreased per iteration for the loop to terminate when it reaches 0.

Input


1. An integer

Output

The first line will contain a message prompt to input the integer.

The succeeding lines contain the odd numbers.

Enter·n:·10
9
7
5
3
1

Expert's answer

#include <stdio.h>


int main()
{
	int n;

	printf("Enter n: ");
	scanf("%d", &n);
	while (n > 0)
	{
		if (n % 2 != 0)
			printf("%d\n", n);
		n--;
	}

	return 0;
}
LATEST TUTORIALS
APPROVED BY CLIENTS