How to print decreasing odd numbers starting from scanf input integer in C?

Gen

If you input even numbers, only the odd numbers will be printed until it reaches 0. (0 will not be printed). For example, if you input 10, the output would be 9, 7, 5, 3, 1.

This is what I came up with. I'm wondering what should I decrement x by to get the desired output.

int x;
scanf("%d", &x);
while (x >= 0) {
  printf("%d", x);
  x = x - 2;
}
Yazid Med
int x, n;


printf("Give N: ");
scanf("%d", &n);

printf("odd numbers from 1 to %d are: \n", n);
x=n;
while(x<=n && x>0)
{
    if(x%2!=0)
    {
        printf("%d\n", x);
    }
    x--;
}

return 0;

}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

How can I print out only odd numbers in an addition loop?

From Dev

How to read hexadecimal numbers from input in C?

From Dev

How to get only odd numbers from a slider?

From Dev

How to check if a sequence of numbers has a increasing/decreasing trend in C++

From Dev

How to get integer input in an array using scanf in C?

From Dev

how to get Even/Odd id numbers from a database table in codeigniter

From Dev

How to do a script for odd and even numbers from 1 to 1000 in Javascript?

From Dev

Finding the Average of all Odd and Even Numbers from an Input/Text File

From Dev

Trying to print even and odd numbers from a shared resource

From Dev

print entered integer from input integer to integer

From Dev

How to let scanf() keep reading integer inputs unless a character is input?

From Dev

How to add odd numbers from a list in python?

From Dev

How to create optional input for scanf in C?

From Dev

How to print odd numbers using recursive java with the limits = n

From Dev

I want to print even and odd number from an input array list

From Dev

Fill double array with random numbers and then print even and odd numbers from that array

From Dev

How to print decreasing odd numbers starting from scanf input integer in C?

From Dev

How to check if a sequence of numbers has a increasing/decreasing trend in C++

From Dev

How does the data flow from input stream into the input buffer during scanf() in C?

From Dev

How to print even numbers in ascending order and odd numbers in descending order without using collection

From Dev

Trying to print even and odd numbers from a shared resource

From Dev

How to list even and odd digits from integer inputs

From Dev

How can i know even and odd numbers from input by user in array? -c

From Dev

How to print a file starting from the nth char?

From Dev

How to print alphabet pyramid starting with user input and descending?

From Dev

How to get Integer and float input without `scanf()` in c?

From Dev

How to find the sum of n odd integers starting from 1?

From Dev

How to avoid spaces, enter key or non-numeric input in C ? scanf reads integer value

From Dev

How do I print numbers starting from 0 to a given input using recursion (details in post)?

Related Related

  1. 1

    How can I print out only odd numbers in an addition loop?

  2. 2

    How to read hexadecimal numbers from input in C?

  3. 3

    How to get only odd numbers from a slider?

  4. 4

    How to check if a sequence of numbers has a increasing/decreasing trend in C++

  5. 5

    How to get integer input in an array using scanf in C?

  6. 6

    how to get Even/Odd id numbers from a database table in codeigniter

  7. 7

    How to do a script for odd and even numbers from 1 to 1000 in Javascript?

  8. 8

    Finding the Average of all Odd and Even Numbers from an Input/Text File

  9. 9

    Trying to print even and odd numbers from a shared resource

  10. 10

    print entered integer from input integer to integer

  11. 11

    How to let scanf() keep reading integer inputs unless a character is input?

  12. 12

    How to add odd numbers from a list in python?

  13. 13

    How to create optional input for scanf in C?

  14. 14

    How to print odd numbers using recursive java with the limits = n

  15. 15

    I want to print even and odd number from an input array list

  16. 16

    Fill double array with random numbers and then print even and odd numbers from that array

  17. 17

    How to print decreasing odd numbers starting from scanf input integer in C?

  18. 18

    How to check if a sequence of numbers has a increasing/decreasing trend in C++

  19. 19

    How does the data flow from input stream into the input buffer during scanf() in C?

  20. 20

    How to print even numbers in ascending order and odd numbers in descending order without using collection

  21. 21

    Trying to print even and odd numbers from a shared resource

  22. 22

    How to list even and odd digits from integer inputs

  23. 23

    How can i know even and odd numbers from input by user in array? -c

  24. 24

    How to print a file starting from the nth char?

  25. 25

    How to print alphabet pyramid starting with user input and descending?

  26. 26

    How to get Integer and float input without `scanf()` in c?

  27. 27

    How to find the sum of n odd integers starting from 1?

  28. 28

    How to avoid spaces, enter key or non-numeric input in C ? scanf reads integer value

  29. 29

    How do I print numbers starting from 0 to a given input using recursion (details in post)?

HotTag

Archive