Sunday, August 23, 2015

Use Break, Continue to find Odd numbers within n Natural Numbers

 Q. 92. Find Odd  Numbers between 1 and "n" using "break" and "continue".



Copy Code:

#include <iostream>

using namespace std;

int main()

{

  int n, i=0 ;

  cout << "Enter a number : ";

  cin >> n ;

  cout << "Odd numbers upto " << n << " are : ";

  do

  {

     ++i ;

     if (i % 2 == 0 )

        continue ;

     cout << i << " " ;

  } while ( i < n) ;

 

return 0;

}

No comments:

Post a Comment