Find Given number is prime or not

Monday, February 15, 2016 Unknown 0 Comments

Find The Given Number Is Prime or Not


#include<iostream>
#include<conio.h>
void main()
{
  int n,i,flag=0;
  cout<<"Enter a positive integer: ";
  cin>>n; 
  for(i=2;i<=n/2;++i)
  {
      if(n%i==0)
      {
          flag=1;
          break;
      }
  } 
  if(flag==0)

      cout<<"This is a prime number"; 
   }
 else
   {
       cout<<"This is not a prime number"; 
   }
 getch(); 
 }
 
Output

Enter a positive integer: 29
This is a prime number.


0 comments:

Simple Single Inheritance

Sunday, February 14, 2016 Unknown 0 Comments

Simple Single Inheritance


Definition: -
                               A class derived from only one base class is called Single inheritance.



#include<iostream.h>
#include<conio.h>

class A
{
    public:
    void showA()
    {
        cout<<"This is class A";
    }
};
class B:public A
{
    public:
    void showB()
    {
        cout<<"\nThis is class B";
    }
};
void main()
{
    B B1;
    clrscr();
    B1.showA();
    B1.showB();
    getch();
}

OUTPUT:


This is class A
This is class B

0 comments: