Sunday, 21 July 2013

Odd Numbers in Ascending Order

// Write a C++ program that prints odd numbers in
// ascending order up to given number.

#include<iostream.h>
#include<conio.h>
void main()
{
    clrscr();
    int i,n;
    cout<<"Enter any number : ";
    cin>>n;
   
    cout<<"\n\n------------------------------------\n";
    cout<<" Odd numbers in Ascending Order \n";
    cout<<"------------------------------------\n";

    if( n%2 == 0 )
    n--;
    for( i = 1 ; i <= n ; i = i+2 )
    cout<<"         "<<i<<endl;
    getch();
}

1 comment: