how to display odd number?

please help my lab practical...

enter 10 integers and display only odd number in a row.
use for loop.
1 Post what you have so far and you may get some help.
2 Only post your question in one forum
Perhaps I shouldn't tell him/her how...

Just a hint then, odd numbers can't be divided by 2. I would have thought that was quite easy...
Last edited on
....you can use % to do it~~~~~
just like chrisname said~~~~~~
odd numbers cannot be divided by 2~~~~~
use % to do it~~~
if the number is even what will be the answers??
if the number is odd what will be the answers??
heres the code
#include<iostream.h>
void main()
{
int a[12];
int i;
cout<<"enter the numbers";
for(i=0;i<=10;i++)
{
cin>>a[i];
}
for(i=0;i<=10;i++)
{
if(a[i]%2!==0)
cout<<a[i];
}
}
Last edited on
ashwani,

1
2
3
4
5
6
7
8
9
10
11
12
int a[12];
int i;
cout<<"enter the numbers";
for(i=0;i<=10;i++)
{
cin>>a[i];
}
for(i=0;i<10;i++)
{
if(a[i]%2!==0)
cout<<a[i];
}

fail.
=.=''' ashwani~~~~ there is no " !== " ~~~~~~

and it should be
1
2
3
4
5
for (int i = 0; i < 10; i++)
{
    if (a[i] % 2 == 1)
         cout << a[i] << " ";
}
~~~~~~
Will you stop with the goddamn tildes?
=.=''' ok
That and the fact that the OP want ten numbers and ashwani's code is set to hold 12, takes 11 as input, then works on the first 10.
ya should declare int a[10] enough
ok girls/guys tq very much....thank god next sem i dont take programming.
to chrisname

i just learn c++ in 2 week so its not easy for me
actually, depending on your programming habbits, you could declare a[10] and start with 1, though you're wasting a very tiny amount of memory. It would be better to get into the habbit of using zero index array, and declare a[9] to hold 10 number. Including the one at a[0].

scratch all of that. My mind isn't fully awake yet this morning.
Last edited on
Aakanaar Wrote:
actually, depending on your programming habbits, you could declare a[10] and start with 1, though you're wasting a very tiny amount of memory. It would be better to get into the habbit of using zero index array, and declare a[9] to hold 10 number. Including the one at a[0].
Are you sure about that?
bah.. too early in the morning.. I'm not thinking. a[10] is correct.
sorry.
Topic archived. No new replies allowed.