Write a function that receives two numbers as an argument and display all prime numbers between these two numbers.

Source 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
34
35
36
37
38
39
40
41
42
#include<iostream>
using namespace std;

void showprime(int, int);

int main()
{

 int x,y;
 cout<<"Enter first  number : ";
 cin>>x;

 cout<<"Enter second  number : ";
 cin>>y;
 showprime(x,y);

 
 return 0;
}

void showprime(int a, int b)
{
 bool flag;

 for(int i=a+1;i<=b;i++)
 {

  flag=false;
  for(int j=2;j<i;j++)
  {

   if(i%j==0)
   {
    flag=true;
    break;
   }
  }

  if(flag==false && i>1)
   cout<<i<<endl;
 }
}

Post a Comment

:) :)) ;(( :-) =)) ;( ;-( :d :-d @-) :p :o :>) (o) [-( :-? (p) :-s (m) 8-) :-t :-b b-( :-# =p~ $-) (b) (f) x-) (k) (h) (c) cheer
Click to see the code!
To insert emoticon you must added at least one space before the code.

 
Top