Pages

Labels

C Program to display odd Number up to 30

Displays all odd number from 1 to 30.

#include<stdio.h>
#include<conio.h>
main() {
    int i;
    for(i=1; i<=30; i+=2) {
        printf("%d\n",i);
    }
}


Output:
1
3
.
.
.
27
29

How it works
Runs by adding 2 on each loop which skips even digits.
1
1 + 2 = 3 
3 + 2 = 5
...
27 + 2 = 29

As we need result up to 30, it will only shows output of odd numbers.

Followers