Inline Function C++ Program to Check a Number can be Express as Sum of Two Prime Numbers
Write a program in C++ to Check Whether a Number can be Express as Sum of Two Prime Numbers using the inline function.
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 | #include<iostream> using namespace std; class T4Tutorials { protected : int n, i, num1,num2,num3,j; public : check(); }; inline T4Tutorials::check() { num1=1,num2=1,num3=0; cout<<"Input a positive integer: "; cin>>n; for(i=3; i<=n/2; i++) { /*prime no?*/ num1=1; num2=1; for(j=2; j<i; j++) { if(i%j==0) { num1= 0;j=i;} } for(j=2; j<n-i; j++) { if((n-i)%j==0) { num2=0;j=n-i;} } if(num1==1 && num2==1) { printf("%d = %d + %d \n",n,i,n-i); num3=1;} } if(num3==0) {printf("\n%d can not be expressed as sum of two prime numbers.\n\n",n);} } int main() { T4Tutorials a; a.check(); } |