Primes & arrays! Mistake?

 NEED TO USE GIVEN OR ELSE FUNCTIONS... Given: Interval of integers [m,n]. Need to use function that recognises primes, need to print all those primenumber pairs that have difference of 2 (m-n=2). I need to use function that recognises primes (as I said before).

The problem:
a,b print strange numbers. When I declare a=0 and b=0 it prints not a primes but 0 and 0.

Need help... :(

Program:

 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556`` `````` #include using namespace std; const int P=23; const int K=40; int pirmskaitli(int[],int k, int f, int n); int main() { int atkartot; int n; int arrr[P]; // array of number int a; int b; do { do { cout << "INT NUMBER OF ELEMENTS " << endl; cin >> n; if (n<2 || n>23 ) cout << "INT NUMBER, THAT IS IN INTERVA; (2;23)!" << P << endl; } while (n<2 || n>23); cout << "INT ALL ELEMENTS: " << endl; for (int i=0; i> arrr[i] ;} if (pirmskaitli(arrr, n, a, b)==5) cout << "------" << endl; else cout << "FOUND PRIMES: " << a << " and " << b << endl; cout << endl << endl << "reply (1) end (0)?" << endl; cin >> reply;} while (reply==1); return 0; } int pirmskaitli (int arrr[], int n, int a, int b) { int arrr2[P]; // array of primes int pair[K]; // pair of numbers int pairx; arrr[0]; for (int i=0;i

in pirmskaili function you passed the value of the integers which means that when the function completed the value of the variable will return to as it was before look at this and compare:
 ``12345678910`` ``````#include using namespace std; void function(int *x,int *y){ //look i passed parameters...so i dont need to return any value *x=*x+1; *y=*y+1;} void main(){ int a=4,b=3; function(&a,&b); cout<<"a value= "<
when you returned from pirmskaitli function of the array and a,n,b never changed because without parameters the computer understand that you to use temporarily and you want the values back ....... use parameters to avoid this
Topic archived. No new replies allowed.