how to display odd number?

Sep 9, 2009 at 5:54pm
please help my lab practical...

enter 10 integers and display only odd number in a row.
use for loop.
Sep 9, 2009 at 5:59pm
closed account (z05DSL3A)
1 Post what you have so far and you may get some help.
2 Only post your question in one forum
Sep 9, 2009 at 6:00pm
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 Sep 9, 2009 at 6:04pm
Sep 10, 2009 at 1:41am
....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??
Sep 10, 2009 at 9:49am
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 Sep 10, 2009 at 11:13am
Sep 10, 2009 at 11:04am
closed account (z05DSL3A)
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.
Sep 10, 2009 at 12:43pm
=.=''' 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] << " ";
}
Sep 10, 2009 at 12:47pm
~~~~~~
Will you stop with the goddamn tildes?
Sep 10, 2009 at 12:57pm
=.=''' ok
Sep 10, 2009 at 1:04pm
closed account (z05DSL3A)
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.
Sep 10, 2009 at 1:21pm
ya should declare int a[10] enough
Sep 14, 2009 at 1:02pm
ok girls/guys tq very much....thank god next sem i dont take programming.
Sep 14, 2009 at 1:24pm
to chrisname

i just learn c++ in 2 week so its not easy for me
Sep 14, 2009 at 2:48pm
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 Sep 14, 2009 at 3:07pm
Sep 14, 2009 at 3:02pm
closed account (z05DSL3A)
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?
Sep 14, 2009 at 3:06pm
bah.. too early in the morning.. I'm not thinking. a[10] is correct.
sorry.
Topic archived. No new replies allowed.