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 .
#include<iostream.h>
#include<conio.h>
#include<process.h>
void main()
{
int a[10],n,pos,i;
clrscr();
cout<<"Enter the no of elements in the array \t";
cin>>n;
cout<<"Enter the elements of the array \t";
for(i=0;i<n;i++)
cin>>a[i];
cout<<"Enter the postion of the number to be checked\t";
cin>>pos;
for(i=2;i<=a[pos+1]/2;i++)
if (a[pos+1]%i==0)
{
cout<<pos<<"th term is not a prime number\t";
getch();
exit(0);
}
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"..
:-/