# Write A C++ Program for...

• Every even number can be expressed as the difference of two primes.

• NOTE : In the case of first prime number that is '2' this condition not gonna satisfy.
/**
*      file :  main.cpp
*      author :  deepak_jangra
*      created :  2021 May 16 11:16:31  IST
*      lastMod :  Sunday 16 May 2021 11:16:31 AM IST
**/
#include<iostream>
using namespace std;
//main funciton
int main()
{
cout<<__func__<<" : Begin"<<endl;
prime p1;
p1.findPrime();
cout<<__func__<<" : End"<<endl;
return 0;
}

• class prime
{
private:
int num;
int prm = 3;
public:
int findPrime();
};
int prime::findPrime()
{
int count = 0;
cout<<"Begin : "<<__func__<<endl;
cout<<"Enter the limit"<<endl;
cin>>num;
for(int i = 5 ; i < num ; i++)
{
for(int j = 2 ; j <= i/2 ; j++)
{
count = 0;
if(i % j == 0)
{
break;
}
else{
if((i - prm) % 2 == 0)
{
cout<<"The difference between "<<i<<" and "<<prm<<" is "<<i - prm<<endl;
prm = i;
break;
}
else
{
cout<<"CONDITION FAILED : The difference between "<<i<<" and "<<prm<<" is "<<i - prm<<endl;
break;
}
}
}
}
cout<<"End : "<<__func__<<endl;
}

• hi @deepak4u106 . if i press terms =17 .so output is
main : Begin
Begin : findPrime
Enter the limit
17
The difference between 5 and 3 is 2
The difference between 7 and 5 is 2
The difference between 9 and 7 is 2
The difference between 11 and 9 is 2
The difference between 13 and 11 is 2
The difference between 15 and 13 is 2
End : findPrime
main : End

and in this programe the 9 number is not a prime number.

•   1 #include<iostream>
2 using namespace std;
3 //main funciton
4
5 class Primeclass
6 {
7   private:
8     int term;
9
10   public:
11     int findPrime();
12         int prime(int);
13 };
14
15 int main()
16 {
17   cout<<__func__<<" : Begin"<<endl;
18   Primeclass p1;
19   p1.findPrime();
20   cout<<__func__<<" : End"<<endl;
21   return 0;
22 }

• int Primeclass::findPrime()
25 {
26   int p,value;
27   cout<<"Begin : "<<__func__<<endl;
28   cout<<"Enter the limit"<<endl;
29   cin>>term;
30   value =2;// if you want any even number for output side .gives the value by user.
31
32   for(int i = term; i > 0; i--)
33   { p=prime(i);
34           if(p == 0)
35           {
36                   for(int j = 1 ;j <i ; j++)
37                   {
38                           p=prime(j);
39                           if (p == 0)
40                           {
41                                   if((i-j)== value)
42                                           cout<<i<<" - "<<j<<" = "<<value<<endl;
43                           }
44                   }
45
46
47
48           }
49   }
50
51
52           return 0;
53
54       }
55   int Primeclass::prime(int x) // this function is use for calculate the prime no.
56   {
57           int i,count=0;
58         for(int i = 2 ;i < x; i++)
59         {
60                 if (x % i ==0 )
61                 {       count++;
62                         return count;
63                 }
64         }
65          return 0;
66
67   }
g++  -o demo main.o getdist.o dispdist.o
/usr/bin/ld: main.o: in function `main':
main.cpp:(.text+0x74): undefined reference to `Distance::addDistance(Distance, Distance)'
collect2: error: ld returned 1 exit status
make: *** [makefile:7: Addition] Error 1