Program to print all odd numbers upto n

Program to print all odd numbers upto n



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// Write a program to print all odd numbers upto n
// Ex: 4 -> 1 3, 5-> 1 3 5
#include
int main(){
    int n,i;
    printf("Enter a integer:");
    scanf("%d",&n); // input from user
    while(n<=0){
         printf("Please enter positive integer only:");
         scanf("%d",&n);      
    }
    printf("Printing even numbers upto %d\n",n); // printing all even numbers
    for(i=1;i<=n;i=i+2){
         printf("%d ",i);
    }
    getch();
}

No comments:

Post a Comment