Skip to content

Commit 461320a

Browse files
authored
Create Range odd.c
1 parent 71a347e commit 461320a

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/* You're given two numbers L and R. Print all odd numbers between L and R (both inclusive) in a single line separated by space, in ascending (increasing) order.
2+
3+
Input:
4+
First-line will contain two numbers L and R.
5+
Output:
6+
Print all odd numbers in a single line separated by space, in ascending (increasing) order.
7+
8+
Constraints
9+
1≤L<R≤106
10+
Sample Input 1:
11+
2 9
12+
Sample Output 1:
13+
3 5 7 9
14+
Sample Input 2:
15+
3 4
16+
Sample Output 2:
17+
3
18+
EXPLANATION:
19+
In the first example, odd numbers between 2 and 9 are 3,5,7,9.
20+
In the second example, the only odd number in the range is 3. */
21+
22+
#include <stdio.h>
23+
24+
int main(void) {
25+
26+
int start , end;
27+
scanf("%d %d",&start,&end);
28+
int a[end];
29+
int x=0;
30+
for(int i=start;i<=end;i++)
31+
{
32+
33+
if(i%2!=0)
34+
{
35+
a[x]=i;
36+
x++;
37+
}
38+
}
39+
40+
for (int y=0;y<x;y++)
41+
{
42+
printf("%d ",a[y]);
43+
}
44+
45+
return 0;
46+
}

0 commit comments

Comments
 (0)