help

Hello i write this func to print the prime number from 2d array
put when i enter for example 1 2 3 4 5 6 7 8 it print 1 2 3 5 7
how can i edit it to not print number 1
this is the code

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
void FindPrime(int o[5][5]){
	  int c[100];int I=0 ,count=0,p =0;
	  int i,j,h;

    for(i =0;i<5;i++)
    {
        for(j =0;j<5;j++)
        {

            count =0;
          for(int k =2;k<o[i][j];k++)
          {
              if(o[i][j]% k == 0)
              {
                  count++;
              }
          }
          if(count == 0)
          {
              c[I] = o[i][j];
			  I++;
			  p++;
          }

        }
    }
    for(int I =0;I<p;I++)
    {
		h=c[I];
		cout<<" "<< h <<"  ";
    }
	cout<<"\n\n";
}
Last edited on
Ah, a followup to: http://www.cplusplus.com/forum/general/226810/

Please use code tags, when posting code. See http://www.cplusplus.com/articles/jEywvCM9/

You have:
1
2
3
4
5
6
7
8
9
count =0;
for (int k =2;k<o[i][j];k++)
{
  if (o[i][j]% k == 0)
  {
    count++;
  }
}
if (count == 0) ...

If the value is 1, then the loop does not iterate (for 2<1 is false) and you effectively have:
1
2
count =0;
if (count == 0) ...


In other words, you need an additional test.
Topic archived. No new replies allowed.