Answer to Question #343963 in C for Ken

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
1
Expert's answer
2022-05-23T10:19:28-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS