Help Fast!! Exam tommorow...

See the Problem in this program is the logic.....
The Question is to display all even numbers in an array and count the no of even numbers.....
The counting part is working fine but i cant display the even numbers...
Note: Use same Functions..
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include<iostream>
int main()
{using namespace std;
int B[100],A[100],i,n,count=0,j=0;
cout<<" Enter the no of numbers you want to enter "<<endl;
cin>>n;
for(i=0;i<n;i++)
{cout<<"Enter number  "<<i<<endl;
cin>>A[i];
}
for(i=0;i<n;i++)
{
if(A[i]%2==0)
{count++;
B[j]=A[i];
j++;
}
}
for(;j<=count;j++)
{cout<<" Even no = "<<B[j]<<endl;
}
cout<<" No of even numbers "<<endl<<count;
return 0;
}
Trace what value of j is when you start the for loop.
squished18
I didn't get you.
Well i tried tracing the value of j , But i am brainwashed right now.
Could you point out the mistake please.
Initialize j=0 in your for loop.

Right now, j = count when you hit your for loop.
cout<<"Thank you it works now ..."<<endl;
cout<<"oh god 1 mistake in C++ = Hard to find";
cout<<"bye";
exit()
}
Topic archived. No new replies allowed.