C++ program to check whether a number is prime or not

//C++ program to check whether a number is prime or not

   #include <iostream>
   #include<conio.h>
   using namespace std;
    int prime(int a)
    {
       int count=0;
      for(int i=2;i<a;i++)
         {
            if(a%i==0)
             {
                 count++;
             }
         }
         if(count==0)
          {
            cout<<"\nThe number "<<a<<" is prime"<<endl;
          }
          else
          {
             cout<<"\nThe number "<<a<<" is not prime"<<endl;
          }
          return a;
    }

 int main()
   {
      int x,i=0;
  //loop to take input 5 time from user
      while(i<5)
      {
      cout<<"Enter a number : ";
      cin>>x;
      prime(x);
      i++;
      }
   }

C++ program to search a number in array

#include<iostream>
using namespace std;

int main()
{
   int array[10],findNum,index,i,j,k=0;
   cout<<"Enter 10 numbers in array : \n";
   for(i=0;i<10;i++)
   {
      cout<<"Enter number "<<i+1<<":  ";
      cin>>array[i];
   }
   cout<<"\n\nEnter number to find in array ";
   cin>>findNum;
   for(j=0;j<10;j++)
   {
      if(findNum==array[j])
      {
       cout<<"\nThe number found in array is "<<array[j]<<endl;
       index=j;
       cout<<"The index of number found in array is "<<index<<endl;
      }
      else
      {
         ++k;
      }
      if(k==10)
      {
         cout<<"\nThe number "<<findNum<<" not found in array "<<endl;
      }
   }
}

C++ program to find maximum and minimum number in array

#include<iostream>
using namespace std;

int main()
{
   int array[10],max,min,i,j,k;
   cout<<"Enter 10 numbers in array : \n";
   for(i=0;i<10;i++)
   {
      cout<<"Enter number "<<i+1<<":  ";
      cin>>array[i];
   }
   max=array[0];
   min=array[0];
   //loop to find maximum No in array
   for(j=1;j<10;j++)
   {
      if(max<array[j])
      {
         max=array[j];
      }

   }
   //loop to find minimum No in array
   for(k=1;k<10;k++)
   {
     if(min>array[k])
      {
         min=array[k];
      }
   }
   cout<<"The maximum number in array is "<<max<<endl;
   cout<<"The minimum number in array is "<<min<<endl;

  return 0;
}

C++ temperature conversion program

#include<iostream>
using namespace std;

 int main()
 {
    int choice;
    float F,C,K;
    cout<<"\nEnter 1 to enter temperature in Centigrade : ";
    cout<<"\nEnter 2 to enter temperature in Fahrenheit : ";
    cout<<"\nEnter 3 to enter temperature in Kelvin : ";
    cout<<"\n\nEnter your choice : ";
    cin>>choice;
    switch(choice)
    {
    case 1:
      {
         cout<<"\nEnter temperature in Centigrade : ";
         cin>>C;
         //  formula to convert centigrade to fahrenheit
         F=(1.8*C)+32;
         //  formula to convert centigrade to kelvin
         K=C+273.15;
         cout<<"\nThe Centigrade temperature in Fahrenheit is = "<<F<<endl;
         cout<<"The Centigrade temperature in Kelvin is = "<<K<<endl;
         break;
      }
    case 2:
      {
         cout<<"\nEnter temperature in Fahrenheit : ";
         cin>>F;
         //  formula to convert fahrenheit to centigrade
         C=0.555*(F-32);
         //  formula to convert fahrenheit to kelvin
         K=0.555*(F-32)+273.15;
         cout<<"\nThe Fahrenheit temperature in Centigrade is = "<<C<<endl;
         cout<<"The Fahrenheit temperature in Kelvin is = "<<K<<endl;
         break;

      }
    case 3:
      {
         cout<<"\nEnter temperature in Kelvin : ";
         cin>>K;
         //  formula to convert kelvin to centigrade
         C=K-273.15;
         //  formula to convert kelvin to fahrenheit
         F=(K-273.15)*1.8+32;
         cout<<"\nThe Kelvin temperature in Centigrade is = "<<C<<endl;
         cout<<"The Kelvin temperature in  Fahrenheit is = "<<F<<endl;
         break;
      }
    default:
      {
         cout<<"You Entered an incorrect choice "<<endl;
      }

    }
    return 0;
 }

C++ program to find GCD and LCM of two numbers

/*GCD of two numbers is the greatest common divisor that
divides both the numbers completely e.g GCD of 15 and 25 is 5.
LCM of two numbers is the product of two numbers divide by its GCD
e.g LCM of 15 and 25 is 15x25/5(gcd)=75 */

#include <iostream>
using namespace std;

int main()
{
   int a,b,gcd,lcm;
   cout<<"Enter two numbers to find its GCD and LCM \n";
   cout<<"Enter first Number ";
   cin>>a;
   cout<<"Enter second Number ";
   cin>>b;

   for(int i=1;i<=a;i++)
   {
      //condition to find highest divisor of both numbers
      if((a%i==0)&&(b%i==0))
      {
         gcd=i;
      }

   }

     cout<<"\nThe GCD Of two numbers "<<a<<" and "<<b<<" is "<<gcd<<endl;
      //formula to find LCM
      lcm=(a*b)/gcd;
     cout<<"The LCM Of two numbers "<<a<<" and "<<b<<" is "<<lcm<<endl;

    return 0;
}


C++ Unique Number program

//C++ unique number program
/*unique No are those No in which no digit is
repeated e.g 123,321 and 12345 are unique Nos*/


#include <iostream>
using namespace std;

int main()
{
//initialize entire array of size 10 to zero
   int arry[10]={0};
   int num,rem,j=0,num1;
   cout<<"Enter number : ";
   cin>>num;
   num1=num;
   while (num!=0)
   {
      rem=num%10;
       //to check all digits of No
      switch(rem){
         case 0:
        ++arry[rem];
           break;
      case 1:
      ++arry[rem];
          break;
      case 2:
         ++arry[rem];
         break;
       case 3:
         ++arry[rem];
         break;
       case 4:
         ++arry[rem];
         break;
       case 5:
         ++arry[rem];
         break;
       case 6:
         ++arry[rem];
        break;
      case 7:
        ++arry[rem];
          break;
      case 8:

         ++arry[rem];
          break;
     case 9:

         ++arry[rem];
         break;

     default:
      cout<<"Enter a valid number "<<endl;
        }

    num=num/10;
   }

  for (int i=0;i<10;i++)
      {
      if (arry[i]>1)
         {

             j++;
         }
      }
    if (j==0)
    {
       cout<<"The number "<<num1<<" is unique "<<endl;
    }
    else
      cout<<"The number "<<num1<<" is not unique "<<endl;

   return 0;
}