#include <stdio.h>
#include <stdlib.h>
void swap(int *a , int *b){
int temp ;
temp = *a ;
*a = *b;
*b = temp;
}
void sort(int arr[] , int n ){
int i , j , min_id ;
for(i = 0 ; i < n-1 ; i++){
min_id = i ;
for(j = i+1 ; j < n ; j++ ){
if(arr[j] < arr[min_id]){
min_id = j;
}
}
swap(&arr[min_id] , &arr[i]);
}
}
int main(void) {
int L , R , n , i , j = 0 , *p , count = 0 ;
scanf("%d %d" , &L,&R);
for(i = L ; i <= R ; i++){
if(i%2 != 0 ){
count++ ;
}
}
p = (int * )malloc(count * sizeof(int));
for(i = L ; i <= R ; i++){
if(i%2 != 0 ){
p[j] = i ;
j++;
}
}
n = sizeof(p)/sizeof(int);
sort(p , n);
for(i = 0 ; i < n ; i++){
printf("%d " , p[i]);
}
return 0;
}
this is outputting only 2 values whereas it should be outputting all the odd values in ascending order within the given range .
eg :> I input 2 and 9 it outputs 3 5
whee as it should output 3 5 7 9