# Odd Numbers in C in a Given Range

## Introduction

In this post, I am going to print odd numbers in c in a given range. I am going to write this program in a number of ways. But before that let us see the expected output.

### Expected Output

``````Enter the range to print odd numbers
10 20
Odd numbers between 10 and 20 are
11 13 15 17 19``````

As you can see the above expected output. We are asking the user to enter the range and then we are displaying the odd numbers between these two numbers.

In this post, I am writing various programs for printing odd numbers in c using different loops.

### C Program to Print Odd Numbers using for loop

``````#include <stdio.h>
#include <stdlib.h>
int main()
{
int a,b,i;
printf("Enter the range to print odd numbers\n");
scanf("%d%d",&a,&b);
printf("Odd numbers between %d and %d are\n",a,b);
for(i=a;i<=b;i++)
{
if(i%2==1)
{
printf("%d ",i);
}
}
return 0;
}``````

### Print Odd Numbers in C using while loop

``````#include <stdio.h>
#include <stdlib.h>
int main()
{
int a,b,i;
printf("Enter the range to print odd numbers\n");
scanf("%d%d",&a,&b);
printf("Odd numbers between %d and %d are\n",a,b);
i=a;
while(i<=b)
{
if(i%2==1)
{
printf("%d ",i);
}
i++;
}
return 0;
}``````

### Print Odd Numbers in C using do while loop

``````#include <stdio.h>
#include <stdlib.h>
int main()
{
int a,b,i;
printf("Enter the range to print odd numbers\n");
scanf("%d%d",&a,&b);
printf("Odd numbers between %d and %d are\n",a,b);
i=a;
do
{
if(i%2==1)
{
printf("%d ",i);
}
i++;
}

while(i<=b);
return 0;
}``````

All the above c programs are printing odd numbers. We have used all three type of loops in c programming for printing our output. I hope you have understood these programs. If you have any difficulties or doubt, please feel free to contact me.

Thank you.