Solved

need simple code to print pair numbers and odd numbers from a previous inserted numbers

Posted on 2003-10-23
4
281 Views
Last Modified: 2010-04-01
need simple code to print pair numbers and odd numbers from a previous inserted numbers
0
Comment
Question by:paStiSSet
  • 2
4 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 9607505
int numbers [] = { ... };

for ( int i = 0; i < sizeof ( numbers); ++i) {

  if ( numbers [ i] % 2) {

      printf ( "%d is odd\n", numbers [ i]);

  } else {

      printf ( "%d is even\n", numbers [ i]);
  }
}
0
 
LVL 1

Author Comment

by:paStiSSet
ID: 9607551
ok is right, so i'm not looking for a code wich has the numbers inserted in the code, the numbers will be inserted by the user who runs the program :)
0
 
LVL 86

Accepted Solution

by:
jkr earned 125 total points
ID: 9607591
#include <iostream>
using namspace std;

int n;

 cout << "Enter a number: ";
 cin >> n;

 if ( n % 2) {

     cout << n " is odd\n" << endl;

 } else {

     cout << n " is even\n" << endl;
 }

:o)
0
 
LVL 9

Expert Comment

by:tinchos
ID: 9607772
Hey paStiSSet

I don't believe that there is any reason to post the same question in 2 different areas

http://oldlook.experts-exchange.com/Programming/Programming_Languages/C/Q_20775992.html
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now