// Write a C++ program that prints odd numbers in
// descending order from a given input.
#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 Descending Order \n";
cout<<"------------------------------------\n";
if( n%2 == 0 )
n--;
for( i = n ; i >= 1 ; i = i-2 )
cout<<" "<<i<<endl;
getch();
}
// descending order from a given input.
#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 Descending Order \n";
cout<<"------------------------------------\n";
if( n%2 == 0 )
n--;
for( i = n ; i >= 1 ; i = i-2 )
cout<<" "<<i<<endl;
getch();
}
how to print odd numbers in ascending and and the in decending order
ReplyDelete