Find Prime Number by another method

  Example Program In C++ #include<iostream> #include<conio.h> #include<math.h> // Math.h For sqrt function using namespace std; int main() { // Variable Declaration int n; // Get Input Value cout<<“Enter the…

Find Prime Number Example Program In C++

  #include<iostream> #include<conio.h> #include<math.h> // Math.h For sqrt function using namespace std; int main() { // Variable Declaration int n; // Get Input Value cout<<“Enter the Number :”; cin>>n; cout<<“List…

Simple Example Program For Namespace In C++

#include <iostream> using namespace std; //Namespace namespacefirst namespace namespacefirst { int value = 5; } //Namespace namespacesecond namespace namespacesecond { double value = 3.1416; } int main () { //Namespace…

Simple Class Example Program For Find Prime Number In C++

#include<iostream>
#include<conio.h>
using namespace std;
// Class Declaration
class prime
{
//Member Varibale Declaration
int a,k,i;
public:
prime(int x)
{
a=x;
}
// Object Creation For Class
void calculate()
{
k=1;
{
for(i=2;i<=a/2;i++)
if(a%i==0)
{
k=0;
break;}
else
{
k=1;
}
}
}
void show()
{
if(k==1)
cout<<”\n”<<a<<” is Prime Number.”;
else
cout<<”\n”<<a<<” is Not Prime Numbers.”;
}
};
//Main Function
int main()
{
int a;
cout<<“Enter the Number:”;
cin>>a;
// Object Creation For Class
prime obj(a);
// Call Member Functions
obj.calculate();
obj.show();
getch();
return 0;
}

Simple Class Example Program In C++

  #include <iostream> #include<conio.h> using namespace std; // Class Declaration class person { //Access - Specifier public: //Varibale Declaration string name; int number; }; //Main Function int main() { //…

Simple Example Program For Copy Constructor In C++

#include<iostream> #include<conio.h> using namespace std; class Example { // Variable Declaration int a,b; public: //Constructor with Argument Example(int x,int y) { // Assign Values In Constructor a=x; b=y; cout<<”\nIm Constructor”;…

Simple Example Program For Constructor Overloading In C++

#include<iostream> #include<conio.h> using namespace std; class Example { // Variable Declaration int a,b; public: //Constructor wuithout Argument Example() { // Assign Values In Constructor a=50; b=100; cout<<”\nIm Constructor”; } //Constructor…

Simple Example Program For Constructor In C++

  #include<iostream> #include<conio.h> using namespace std; class Example { // Variable Declaration int a,b; public: //Constructor Example() { // Assign Values In Constructor a=10; b=20; cout<<“Im Constructor\n”; } void Display()…

Do While Loop Example Program In C++

  #include<iostream> #include<conio.h> using namespace std; int main() { // Variable Declaration int a; // Get Input Value cout<<“Enter the Number :”; cin>>a; int counter = 1; //Do while Loop…