C Programming Code Examples C > For Loops and While Loops Code Examples Program to display odd numbers without using if statement Program to display odd numbers without using if statement Logic to print odd numbers from 1 to n without if statement The above approach is not optimal approach to print odd numbers. Observe the above program for a while. You will notice that, I am unnecessarily iterating for even numbers, which is not our goal. Input upper limit to print odd number from user. Store it in some variable say N. Run a loop from 1 to N, increment it by 2 for each iteration. The loop structure should look like for(j=1; j<=N; j+=2). Inside the loop body print the value of j. /* C program to display all odd numbers between 1 to n without using if statement */ #include <stdio.h> int main() { int j, n; /* Input upper limit from user */ printf("Print odd numbers till: "); scanf("%d", &n); printf("All odd numbers from 1 to %d are: \n", n); /* Start a loop from 1, increment it by 2. For each repetition prints the number. */ for(j=1; j<=n; j+=2) { printf("%d\n", j); } return 0; }