Where is the problem

Where is the problem ı can't get it.My output like ==venss-858993460evenss-858993460evenss-858993460evenss-858993460evenss-858993460evenss-858993460evenss-858993460odds-858993460odds-858993460odds-858993460Press any key to continue . . .






1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
  #include<math.h>
#include<iostream>
using namespace std;

int main()
{

	int a[10] = { 2,4,5,70,45,48,49,50,54,100 };
	int counterEven = 0;
	int counterOdd = 0;
	int evenArray[10];
	int oddArray[10];
	int k = 0, l = 0;
	int i;

	for (i = 0; i <= 9; i++)
	{
		if (a[i] % 2 == 0)
		{

			a[k] = evenArray[i];
			k++;
		
		}
		if (a[i] % 2 == 1)
		{
			a[l] = oddArray[i];
			l++;
		
		}

	}

	for (i = 0; i <= k - 1; i++)
	{
		cout << "evenss" << evenArray[i];
		
	}

	for (i = 0; i <= l - 1; i++)
	{
		cout << "odds" << oddArray[i];

	}




	system("pause");




}
closed account (SECMoG1T)
i think you meant to do this the other way round
1
2
3
4
5
6
7
8
9
10
11
12
13
if (a[i] % 2 == 0)
		{

			a[k] = evenArray[i];///error here, evenArray[i]=a[k] maybe
			k++;
		
		}
		if (a[i] % 2 == 1)
		{
			a[l] = oddArray[i];//error here
			l++;
		
		}
Nope.Still same :(
closed account (SECMoG1T)
try this
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include<cmath>
#include<iostream>


int main()
{

	int a[10] = { 2,4,5,70,45,48,49,50,54,100 };
	int counterEven = 0;
	int counterOdd = 0;
	int evenArray[10]{};
	int oddArray[10]{};


	for (int i = 0; i <= 9; i++)
	{
		if (a[i] % 2 == 0)
		 {
		       evenArray[counterEven] = a[i];
			++counterEven;
                  }

		else
		 {
		     oddArray[counterOdd] = a[i] ;
		     ++counterOdd;
                 }
	}

        std::cout<<"Evens:\n";
	
       for (int i = 0; i <counterEven; i++)
	{
	    std::cout <<evenArray[i]<<" ";
	}

	std::cout<<"\n\nOdds:\n";
	
        for (int i = 0; i <counterOdd; i++)
	{
	    std::cout << oddArray[i]<<" ";
	}

        std::cout<<"\n\n";

	system("pause");
}
Last edited on
Thank you...
Topic archived. No new replies allowed.