how to display odd number?

annelisse (3)
please help my lab practical...

enter 10 integers and display only odd number in a row.
use for loop.
Grey Wolf (3172)
1 Post what you have so far and you may get some help.
2 Only post your question in one forum
chrisname (5896)
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
loveless (56)
....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??
ashwani (15)
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
Grey Wolf (3172)
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.
loveless (56)
=.=''' 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] << " ";
}
helios (10126)
~~~~~~
Will you stop with the goddamn tildes?
loveless (56)
=.=''' ok
Grey Wolf (3172)
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.
loveless (56)
ya should declare int a[10] enough
annelisse (3)
ok girls/guys tq very much....thank god next sem i dont take programming.
annelisse (3)
to chrisname

i just learn c++ in 2 week so its not easy for me
Aakanaar (166)
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
Grey Wolf (3172)
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?
Aakanaar (166)
bah.. too early in the morning.. I'm not thinking. a[10] is correct.
sorry.
Topic archived. No new replies allowed.