Monday, December 1, 2014

Linear search in C++ program & Search Number in c++ pro



Find GCD of two numbers

#include
#include
using namespace std;
int main()
{

int first_number;
cout<<"Enter First Number : ";cin>>first_number;
int  second_number;
cout<<"Enter Second Number: ";cin>>second_number;
int  gcd;
for(int i=1;i<=first_number&&i<=second_number;i++)
    {
     if(first_number%i==0 && second_number%i == 0 )
    {

                    gcd=i;
   }
}
cout<<"Greatest Common Divison (GCD):"<
return 0;
}

C++ program to reverse a number

#include
#include
using namespace std;
int main()
 {
int number, reverse = 0;
cout<<"Input a Number to Reverse and press Enter: ";
 cin>> number;    
   for( ; number!= 0 ; )
   {
      reverse = reverse * 10;
      reverse = reverse + number%10;
      number = number/10;
   }
   cout<<"New Reversed Number is:  "<
   return 0;
}

Linear search in C++ program

#include
#include
using namespace std;
int main()
{
cout<<"Enter the size of array:   ";
int size;
cin>>size;
int array[size], key,i;
 for(int j=0;j
{
 cout<<"Enter "<
 cin>>array[j];
 }
 for(int a=0;a
  {
     if(key==array[i])
  {
  cout<<"Key Found At Index Number :  "<
  break;
   }
 }
if(i != size)
{
cout<<"Key found at index :  "<
}
else
{
cout<<"Key not found in Array ";
}
   return 0;
}

No comments:

Post a Comment