Outputtign Odd numbers

I want to output odd number using arrays. I have this solution working, but for general knowledge, can I improve this code more. if I can't, is there another way to output numbers using one dimension arrrays

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
  
	int odd[10];
	int i;
	int k;
	k=0;

	for (i=1;i<10;i=i+2)
	{
		
		
		odd[k]=i;
		cout<<odd[k];
			k++;
	}
	_getch();
	return 0;
}
The only thing I currently see that can be "improved" is modifying i=i+2 with i += 2, but it's not an actual mistake.

I know it's probably not what you were looking for, but I can't think properly at this time of the night.
That's alright :) better then recieving a no answer. Thanks!
How about this?

1
2
3
4
5
6
7
8
	int odd[5];
	int i = 0;

	for(i=0; i<5; i++)
	{
		odd[i] = 1 + (i*2);
		cout << odd[i];
	}
Last edited on
Not bad home star! Creative thinking, I must say
Topic archived. No new replies allowed.