C Program to Generate Odd Numbers Between Two Integers


C program to generate odd numbers between 2 integer values input by the user.

Related Read:
Even or Odd Number: C Program
Even or Odd Number without using Modular Division: C Program

Note 1: An odd number is an integer that is not exactly divisible by 2.

Note 2: Odd numbers are of the form (2 * n + 1);

Note 3: Modular division( % ) returns remainder of division. For example, 10 / 2 = 5. But 10 % 2 = 0.

C Program to Generate Odd Numbers Between Two Integers

 
#include<stdio.h>

int main()
{
    int count, limit;

    printf("Enter start and end value to generate Odd numbers\n");
    scanf("%d%d", &count, &limit);

    printf("\nOdd numbers between %d and %d are:\n", count, limit);

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

    return 0;
}

Output 1
Enter start and end value to generate Odd numbers
10
30

Odd numbers between 10 and 30 are:
11
13
15
17
19
21
23
25
27
29

Output 2
Enter start and end value to generate Odd numbers
1
10

Odd numbers between 1 and 10 are:
1
3
5
7
9

C Program to Generate Odd Numbers Between Two Integers


[youtube https://www.youtube.com/watch?v=vPzV7pE0Djw]

YouTube Link: https://www.youtube.com/watch?v=vPzV7pE0Djw [Watch the Video In Full Screen.]


In above c program, we ask the user to input 2 integer value and store it in variables count and limit. While loop keeps executing until the start value i.e., count is less than or equal to the end value i.e., limit.

Inside while loop, for every value of count, we check if its not perfectly divisible by 2. If true, it’s a Odd number and we output that number to the console window. On every iteration of the loop we increment the value of count by 1.

For list of all c programming interviews / viva question and answers visit: C Programming Interview / Viva Q&A List

For full C programming language free video tutorial list visit:C Programming: Beginner To Advance To Expert

Leave a Reply

Your email address will not be published. Required fields are marked *