solved  how to display odd number?

annelisse (3)   Link to this post
please help my lab practical...

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

i just learn c++ in 2 week so its not easy for me
Aakanaar (166)   Link to this post
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 (1609)   Link to this post
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)   Link to this post
bah.. too early in the morning.. I'm not thinking. a[10] is correct.
sorry.

This topic is archived - New replies not allowed.