Write a program in C++ to find the prime numbers within a range of numbers by using the Virtual base Class in Object Oriented Programming(OOP).
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 43 44 45 46 47 48 49 |
#include<iostream> using namespace std; class A { protected: int i,n; }; class B:virtual public A { protected: int T4Tutorials_StartingNum,T4Tutorials_EndigNum; }; class C:virtual public A { protected: int c; }; class D:public B,public C { public: int prime() { cout<<"enter starting no rnge"<<endl; cin>>T4Tutorials_StartingNum; cout<<"enter ending no rnge"<<endl; cin>>T4Tutorials_EndigNum; cout<<"the prime numbers btw"<<T4Tutorials_StartingNum<<" "<<T4Tutorials_EndigNum<<" "; for(n=T4Tutorials_StartingNum;n<=T4Tutorials_EndigNum;n++) { c=
0; for(i=2;i<=n/2;i++) { if(n%i==0) { c++; break; } } if(c==0&&n!=1) cout<<n<<" "; } cout<<endl; } }; int main() { D obj; obj.prime(); } |
FAQ
prime number program in c++ using class and object by using the Virtual base Class in Object Oriented Programming(OOP).
c++ program to print prime numbers up to n by using the Virtual base Class in Object Oriented Programming(OOP).
c++ program to find n prime numbers by using the Virtual base Class in Object Oriented Programming(OOP).
check whether the number is prime or not in c++ by using the Virtual base Class in Object Oriented Programming(OOP).
write a c++ program by using forloop to find that a number is prime or not a prime by using the Virtual base Class in Object Oriented Programming(OOP).
fastest way to check if a number is prime c++ by using the Virtual base Class in Object Oriented Programming(OOP).