Saturday, November 29, 2014

largest number & minimum number in array in c++



check the entered character is capital letter, small letter, digit or a special character
  
#include
 #include
int main()
{
  char character;
  cout<<"enter a character =  ";
    cin>>character;
  int storeascii=character;
  cout<<"the ascii value  of "<   if (storeascii>=65 && storeascii<=90)
  {
    cout<<"\nyou have entered a capital letter";
  }

  else if (storeascii>=97 && storeascii<=122)
  {
    cout<<"\nyou have entered a small letter";
  }

  else if (storeascii>=47 && storeascii<=57)
  {
    cout<<"\nyou have entered a digit ";
  }

  else if
   (storeascii>=0 && storeascii>=47
    storeascii>=54 && storeascii<=64
    storeascii>=91 && storeascii<=96
    storeascii>=123 && storeascii<=127)
  {
    cout<<"\nyou have entered a special character";
  }

return 0;
}

Maximum or largest number in array c++ code

  #include
  #include
 int main()
    {
    cout<<"enter the size of array:   ";
    int size;
    cin>>size;
    int array[size], key,i;

taking input in array
    for(int j=0;j
{
    cout<<"enter "<     cin>>array[j];
    }
   your entered array is
    for(int a=0;a
{

          if(array[i]>maximum)
{
              maximum=array[i];
          }
    }

   cout<<"\n\nmaximum number is in array is :"<    return 0;
 }

Find maximum and minimum number in array c++ code

#include
#include
#include
 int main()
{
     const int size=50;
     array with size of 50
     int array[size];
    for random numbers
    srand(time(0));
    for(int i=0;i
{
     initializing array number is less than 100
     array[i]=rand()%100;
    displaying array value
    cout<
}
     initializing max, min
                int max=array[0];
                int min=array[0];
    scanning array to find
    minimum and maximum
    number 
   for(int i=0;i
{
    finding minimum number in array
      if(min>array[i])
{
         min=array[i];
      }
    finding maximum number in array
      if(max
{
      max=array[i];
      }
}
     displaying output
        cout<<"maximum number is :"<         cout<<"minimum number  is:"<
   return 0;
}

Reverse a Number & recursive function c++



Linear Search in C++ Program Example Code

#include
#include
     int main()
    {
cout<<"enter the size of array:   ";
int size;
cin>>size;
int array[size], key,i;
 taking input in array
 for(int j=0;j
{
 cout<<"enter "<
 cin>>array[j];
 }
your entered array is
 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;
}

Reverse a Number in C++ Program Code
   
     #include
     #include
int main()
{
int number, reverse = 0;
cout<<"input a number to reverse and press enter: ";
 cin>> number; 
 taking input number in variable number
   for( ; number!= 0 ; )
   {
      reverse = reverse * 10;
      reverse = reverse + number%10;
      number = number/10;
   }
   cout<<"new reversed number is:  "<    return 0;
}

C++ program linear search program using recursive function

 #include
 #include
int recursivelinearsearch(int array[],int key,int size)
{
    size=size-1;
      if(size <0 span="">
{
      return -1;
      }
      else if(array[size]==key)
{
      return 1;
      }
      else
{
      return recursivelinearsearch(array,key,size);
      }
    }


    int main()
 {
    cout<<"enter the size of array:   ";
    int size;
    cin>>size;
    int array[size], key,i;
   taking input in array
    for(int j=0;j
{
    cout<<"enter "<
    cin>>array[j];
 }
   your entered array is
  for(int a=0;a
{
       cout<<"array[ "<  =  ";
       cout<
    }
    cout<<"enter key to search  in array";
    cin>>key;
    int result;
result=recursivelinearsearch(array,key,size--);
    if(result==1)
{
    cout<<"key found in array  ";
    }
    else
{
    cout<<"key not found in array  ";
    }
       return 0;
    }

Palindrome & Armstrong Number in c++



Find Palindrome number in c++

#include
 #include
int main()
{
    int palindrome, reverse=0;
    cout<<"enter number:  ";
    cin>>palindrome;
    int num=0,key=palindrome;
   for(int i=1;palindrome!=0;i++)
   {
    num=palindrome%10;
    palindrome=palindrome/10;
    reverse=num+(reverse*10);
         }
         if(reverse==key)
       {
       cout<
        }
            else
    {
   cout<
    }
return 0;
}

C++ program which takes input a number and check whether it is Armstrong Number or not

  #include
 #include
  int main()
  {
  int armstrong=0,num=0,result=0,check;
  cout<<"enter number to find it is an armstrong number?";
       cin>>num;
       check=num;
       for(int i=1;num!=0;i++)
{
       armstrong=num%10;
        num=num/10;
        armstrong=armstrong*armstrong*armstrong;
        result=result+armstrong;
       }
       if(result==check)
{
       cout<  is an armstrong number";
       }
       else
{
       cout<  is not an armstrong number";
       }
       return 0;
    }

To print right triangle shape using nested for loops

#include
#include
 int main()
{
   for(int i=0;i<=5;i++)
         {

        for(int j=0;j<=i;j++)
            {
                cout<             }
       cout<     }
 return 0;
}

Find Greatest Common Divisor (GCD) of two numbers c++ program

 #include
 #include
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;
}