hey friends, here is a code that I made to find the prime numbers in an array.. What the program is supposed to do is check whether the number is PRIME or not.. The position of the element is specified and the program finds and check the element in that position.. Unfortunately it is not working properly.. no error while compiling yet there are some other logic errors I guess.. please help me sort it out

I tried to debug.. But it didn't help .

void main()
int a[10],n,pos,i;
cout<<"Enter the no of elements in the array \t";
cout<<"Enter the elements of the array \t";
cout<<"Enter the postion of the number to be checked\t";
if (a[pos+1]%i==0)
cout<<pos<<"th term is not a prime number\t";
cout<<pos<<"th term is a prime number\t";
getch(); return;

I added a watch on "g" which is the variable which contains the value of a[pos +1] .The value of g is not changing.. It is some random value like 1336...
the problem is with assigning the value of a[pos+1] to the variable "g"..


pos+1 ??
should it be pos-1?

For say if array is int arr= {5,4,8,7}
and you are checking at position 4 i.e 7,
then you should do arr[3] and no arr[5] since
also, arr[5] is not equal to 7 but it contains some junk values!!

so just change pos+1 to pos-1 and then chekc

My god..! You are a genius..! Why didn't I think of that..! phew..! Thank you so much dear friend.! I cant thank you enough..! The problem is eventually solved..!

This question has already been answered. Start a new discussion instead.