print prime numbers between any tow number

hi you
I write program print prime number between any tow numbers using recursion function
but I have problem in code
please help me

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
  #include<iostream>
using namespace std;
int prime(int m,int n);
int main(){
int m, n, p, i, isPrime = true;
cout << "Enter two numbers" << endl;
cin >> m >> n;
int prime(int m,int n);
if(n > m){
for(p = m; p <= n; p ++){
isPrime = true;
for(i = 2; i < p; i++){
if(p % i == 0){
isPrime = false;
}
}
if(isPrime){
cout << prime(int m,int n) << endl;
}
}
}
}
Last edited on
I am waiting to you reply

1) use indenting style code source ( imo best style is Allman )
https://en.wikipedia.org/wiki/Indent_style

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
34
#include<iostream>
using namespace std;

int prime( int m , int n ) ;

int main()
{
	int m, n, p, i, isPrime = true ;

	cout << "Enter two numbers" << endl;

	cin >> m >> n;

	int prime(int m,int n);

	if( n > m )
	{
		for( p = m ; p <= n ; p ++ )
		{
			isPrime = true;
			for( i = 2 ; i < p ; i++ )
			{
				if( p % i == 0 )
				{
					isPrime = false;
				}
			}
			if(isPrime)
			{
				cout << prime(int m,int n) << endl;
			}
		}
	}
}



2)line 14 = line 4 : duplicate declaration of function "prime( int , int )"

3)line 30: call function "prime( int m , int n )": function call incorrectly;

4) the function "prime (int,int)" never defined
Last edited on
maybe I understood..

please read tutorial for learning function c++:
http://www.cplusplus.com/doc/tutorial/functions/
Last edited on
hi ar2007
when I run it , it don't output
what do you do?
when I run it , it don't output

It doesn't output because it won't even compile.
As ar2007 pointed out in #3, you don't specify types when making a function call.

And #4, you have a function declaration for prime(), but you've never defined prime(). This is going to cause a linker error (once you fix the compile errors).

what do you do?

1) Fix the compile errors.
2) Define the function prime() so you don't get an undefined symbol at link time.
Last edited on
ok I want to correct code
Topic archived. No new replies allowed.