arrow
arrow

Arrays

Input and Output of the arrays


                            
                                #include<iostream>
                                    #include<cstdlib>
                                    #include<ctime>
                                    using namespace std;
                                    int main()
                                    {  int x=time(0);
                                        srand(x);
                                        const int size=100;
                                        int arr[size]={};
                                         int max=arr[0];
                                         int min;
                                        for(int i=0;i<10;i++){
                                            arr[i]=(rand()%100)+1;
                                        }
                                        for(int i=0;i<10;i++){
                                            cout<<arr[i]<<" ";
                                        }}    
                            
                        

Write a C++ program to print all negative elements in the array.


                        
                            #include<iostream>
                                using namespace std;
                                int main()
                                {
                                    const int size=10;
                                    int arr[size];
                                    cout<<"Enter the numbers:"<<endl;
                                    for(int i=0;i<size;i++){
                                        cin>>arr[i];
                                    }
                                    cout<<"The negative elements in the array = "<<endl;
                                    for(int i=0;i<size;i++){
                                        if(arr[i]<0)
                                        {
                                          cout<<arr[i]<<" ";
                                        } 
                                    }
                                    return 0;
                                }
                        
                    

Write a C++ program to find sum of all elements in the array.


                        
                            #include<iostream>
                                using namespace std;
                                int main()
                                {
                                    const int size=10;
                                    int arr[size];
                                    int sum=0;
                                    cout<<"Enter the numbers:"<<endl;
                                    for(int i=0;i<size;i++){
                                        cin>>arr[i];
                                        sum=sum+arr[i];
                                    }
                                    cout<<"The sum of all the elements in the array = "<<sum<<endl;
                                 
                                    
                                    return 0;
                                }
                        
                    

Write a C++ program to find the largest and smallest element in the array.


                        
                            #include<iostream>
                                using namespace std;
                                int main()
                                {
                                    const int size=4;
                                    int arr[size];
                                    int max;
                                    int min;
                                    cout<<"Enter the numbers:"<<endl;
                                    for(int i=0;i<size;i++){
                                        cin>>arr[i];
                                    }
                                     max=arr[0];
                                     min=arr[0];
                                    for(int i=0;i<size;i++){
                                         if(max<arr[i])
                                         {
                                             max=arr[i];
                                         }
                                         if(min>arr[i])
                                         {
                                             min=arr[i];
                                         }
                                    }
                                    cout<<"The maximum between these numbers = "<<max<<endl;
                                    cout<<"The minimum between these numbers = "<<min<<endl;
                                    return 0;
                                }
                        
                    

Write a C++ program to find the Second largest element in the array.


                        
                            #include<iostream>
                                #include<cstdlib>
                                #include<ctime>
                                using namespace std;
                                int  main()
                                {
                                  const int size=10;
                                  int arr[size];
                                  int firstMax;
                                  int secondMax;
                                  int x=time(0);
                                  srand(x);
                                  for(int i=0;i<size;i++){
                                      arr[i]=(rand()%10)+1;
                                  }
                                  for(int i=0;i<size;i++){
                                      cout<<arr[i]<<" ";
                                  }
                                  firstMax=arr[0];
                                  secondMax=arr[0];
                                  for(int i=0;i<size;i++){
                                    if(firstMax<arr[i])
                                    {
                                        firstMax=arr[i];
                                    }
                                  }
                                  for(int i=0;i<size;i++){
                                      if(arr[i]==firstMax)
                                      {
                                          continue;
                                      }
                                      else 
                                      {
                                          if(secondMax<arr[i])
                                          {
                                              secondMax=arr[i];
                                          }
                                      }
                                  }
                                  cout<<"The second largest element in the array = "<<secondMax<<endl;
                                
                                    return 0;
                                }
                                /*legal way is that firstly you sort the array and then find the 2nd largest and 2nd smallest by 
                                by the index print 2nd */
                        
                    

Write a c++ program to insert the element in the end of the array.


                        
                            #include<iostream>
                                #include<cstdlib>
                                #include<ctime>
                                using namespace std;
                                int  main()
                                {
                                  const int size=11;
                                  int arr[size];
                                  int num;
                                  int x=time(0);
                                  srand(x);
                                  for(int i=0;i<10;i++){
                                      arr[i]=(rand()%10)+1;
                                  }
                                  for(int i=0;i<10;i++){
                                      cout<<arr[i]<<" ";
                                  }
                                  cout<<endl;
                                  cout<<"Enter the element that you want to be insert :"<<endl;
                                  cin>>num;
                                  for(int i=0;i<size;i++){
                                      if(i==10)
                                      {
                                          arr[i]=num;
                                      }
                                      cout<<arr[i]<<" ";
                                  }
                                  return 0;
                                }
                        
                    

Write a c++ program to insert the element at the specific position.


                        
                            #include<iostream>
                                #include<cstdlib>
                                #include<ctime>
                                using namespace std;
                                int main()
                                {
                                  const int size=11;
                                  int arr[size];
                                  int num;
                                  int pos;
                                  int x=time(0);
                                  srand(x);
                                  for(int i=0;i<10;i++){
                                      arr[i]=(rand()%10)+1;
                                  }
                                  for(int i=0;i<10;i++){
                                      cout<<arr[i]<<" ";
                                  }
                                  cout<<endl;
                                  cout<<"Enter the element that you want to be insert :"<<endl;
                                  cin>>num;
                                  cout<<"Enter the specific position that you want to insert :"<<endl;
                                  cin>>pos;
                                  for(int i=size;i>pos-2;i--){
                                     arr[i]=arr[i-1];
                                    if(i==pos-1)
                                      {
                                          arr[i]=num;
                                      }
                                  }
                                  cout<<"The inserted array at the specific position = "<<endl;
                                  for(int i=0;i<size;i++){
                                      cout<<arr[i]<<" ";
                                  }
                                    return 0;
                                }
                        
                    

Write a c++ program to delete the element at the specific position.


                        
                            #include<iostream>
                                #include<cstdlib>
                                #include<ctime>
                                using namespace std;
                                int main()
                                {
                                  const int size=10;
                                  int arr[size];
                                  int num;
                                  int pos;
                                  int x=time(0);
                                  srand(x);
                                  for(int i=0;i<size;i++){
                                      arr[i]=(rand()%10)+1;
                                  }
                                  for(int i=0;i<size;i++){
                                      cout<<arr[i]<<" ";
                                  }
                                  cout<<endl;
                                  cout<<"Enter the specific position that you want to delete :"<<endl;
                                  cin>>pos;
                                  for(int i=pos-1;i<size-1;i++){
                                      arr[i]=arr[i+1];
                                  }
                                  cout<<"The deleted array = "<<endl;
                                  for(int i=0;i<size-1;i++)
                                  {
                                      cout<<arr[i]<<" ";
                                  }
                                
                                  return 0;
                                }
                        
                    

Write a C++ Program to count the frequncy of the elements in the array.


                        
                            #include<iostream>
                                using namespace std;
                                int main()
                                {
                                
                                  const int size=10;
                                  int arr[size];
                                  int freq[size]={0};//Initailize the whole array of frequency with zero
                                  int count;
                                  cout<<"Enter the elements of the array :"<<endl;
                                  for(int i=0;i<size;i++){
                                      cin>>arr[i];
                                  }
                                  cout<<"The elements that you want to be enter = "<<endl;
                                  for(int i=0;i<size;i++){
                                      cout<<arr[i]<<" ";
                                  }
                                  cout<<"The frequency of each element = "<<endl;
                                  //outer loop controls the number index that frequenct can be counted
                                  for(int i=0;i<size;i++ ){
                                      count=1;//intitalize to 1 beacuse every number must have a minimum frequency of 1
                                      for(int j=i+1;j<=size;j++)//inner loop starts from the i+1 to campare it with nrext index element
                                      {
                                           if(arr[i]==arr[j])//comparsion
                                           {
                                               count++;
                                               freq[j]=-1;//this is very imporatnt concpet that if number repeats than it iniliathe the next index of freq with -1
                                               //to not repeat the it 
                                           }
                                      }
                                      if(freq[i]!=-1)//if index is not equal to -1 than its value of freq is equal to the count
                                      {
                                          freq[i]=count;
                                      }
                                  }
                                  for(int i=0;i<size;i++)
                                  {
                                      //if eveery those index of freq that have not the -1 repeated index we just printed only these values
                                      if(freq[i]!=-1)
                                      {
                                          cout<<"The number "<<arr[i]<<" has  frequency of "<<freq[i]<<endl;
                                      }
                                  }
                             
                                    return 0;
                                }
                        
                    

Write a C++ program print all unique elements in the array.


                        
                            #include<iostream>
                                using namespace std;
                                int main()
                                {
                                
                                  const int size=10;
                                  int arr[size];
                                  int freq[size]={0};//Initailize the whole array of frequency with zero
                                  int count;
                                  cout<<"Enter the elements of the array :"<<endl;
                                  for(int i=0;i<size;i++){
                                      cin>>arr[i];
                                  }
                                  cout<<"The elements that you want to be enter = "<<endl;
                                  for(int i=0;i<size;i++){
                                      cout<<arr[i]<<" ";
                                  }
                                  cout<<"The unique elements are = "<<endl;
                                  //outer loop controls the number index that frequenct can be counted
                                  for(int i=0;i<size;i++ ){
                                      count=1;//intitalize to 1 beacuse every number must have a minimum frequency of 1
                                      for(int j=i+1;j<=size;j++)//inner loop starts from the i+1 to campare it with nrext index element
                                      {
                                           if(arr[i]==arr[j])//comparsion
                                           {
                                               count++;
                                               freq[j]=-1;//this is very imporatnt concpet that if number repeats than it iniliathe the next index of freq with -1
                                               //to not repeat the it 
                                           }
                                      }
                                      if(freq[i]!=-1)//if index is not equal to -1 than its value of freq is equal to the count
                                      {
                                          freq[i]=count;
                                      }
                                  }
                                  for(int i=0;i<size;i++)
                                  {
                                      //if element have frequency 1  we just printed only these values
                                      if(freq[i]==1)
                                      {
                                          cout<<arr[i]<<" ";
                                      }
                                  }
                                    return 0;
                                }
                        
                    

Write a C++ program to count number of duplicate elements in the array.


                        
                            #include<iostream>
                                using namespace std;
                                int main()
                                {
                                
                                  const int size=10;
                                  int arr[size];
                                  int freq[size]={0};//Initailize the whole array of frequency with zero
                                  int count;
                                  cout<<"Enter the elements of the array :"<<endl;
                                  for(int i=0;i<size;i++){
                                      cin>>arr[i];
                                  }
                                  cout<<"The elements that you want to be enter = "<<endl;
                                  for(int i=0;i<size;i++){
                                      cout<<arr[i]<<" ";
                                  }
                                  cout<<"The unique elements are = "<<endl;
                                  //outer loop controls the number index that frequenct can be counted
                                  for(int i=0;i<size;i++ ){
                                      count=1;//intitalize to 1 beacuse every number must have a minimum frequency of 1
                                      for(int j=i+1;j<=size;j++)//inner loop starts from the i+1 to campare it with nrext index element
                                      {
                                           if(arr[i]==arr[j])//comparsion
                                           {
                                               count++;
                                               freq[j]=-1;//this is very imporatnt concpet that if number repeats than it iniliathe the next index of freq with -1
                                               //to not repeat the it 
                                           }
                                      }
                                      if(freq[i]!=-1)//if index is not equal to -1 than its value of freq is equal to the count
                                      {
                                          freq[i]=count;
                                      }
                                  }
                                  for(int i=0;i<size;i++)
                                  {
                                      //if element have frequency 2  we just printed only these values
                                      if(freq[i]==2)
                                      {
                                          cout<<arr[i]<<" ";
                                      }
                                  }
                                
                                    return 0;
                                }
                        
                    

Write a c++ progarm to copy the one array into the another array.


                        
                            #include<iostream>
                                #include<cstdlib>
                                #include<ctime>
                                using namespace std;
                                int  main()
                                {
                                  const int size=10;
                                  int arr[size];
                                  int copy[size]={0};
                                  int x=time(0);
                                  srand(x);
                                  for(int i=0;i<size;i++){
                                      arr[i]=(rand()%10)+1;
                                  }
                                  for(int i=0;i<size;i++){
                                      cout<<arr[i]<<" ";
                                  }
                                  cout<<endl;
                                  cout<<"The uncopied array = ";
                                  for(int i=0;i<size;i++){
                                      cout<<copy[i]<<" ";
                                  }
                                  cout<<endl;
                                  cout<<"The copied array = ";
                                  for(int i=0;i<size;i++){
                                      copy[i]=arr[i];
                                  }
                                  for(int i=0;i<size;i++){
                                      cout<<copy[i]<<" ";
                                  }
                                  return 0;
                                }
                        
                    

Write a C++ program to delete all the duplicate elements in the array:


                        
                            #include <iostream>
                                using namespace std;
                                int main()
                                {
                                    int size = 10;
                                    int arr[size] = {};
                                    cout << "Enter the elemnts in the array:" << endl;
                                    for (int i = 0; i < size; i++)
                                    {
                                        cin >> arr[i];
                                    }
                                    for (int i = 0; i < size; i++)
                                    {
                                        cout << arr[i] << " ";
                                    }
                                    for (int i = 0; i < size; i++)
                                    { // outer loop i can control the index that can be compared to be repeated or not
                                        for (int j = i + 1; j <= size; j++)
                                        { // innner loop j can be control the index with the i index can be compared
                                            if (arr[i] == arr[j])
                                            {
                                                for (int k = j; k <= size; k++)
                                                {                        // most inner loop k can shift the array to overwrite the repeated index with the next index element
                                                    arr[k] = arr[k + 1]; // when we can shift the array the size of array after one iteration of k became size-1
                                                }
                                                size--; // so write as size-- after the shifting of an full array
                                            }
                                        }
                                    }
                                    cout << "The latest array is here:" << endl;
                                    for (int i = 0; i < size; i++)
                                    {
                                        cout << arr[i] << " ";
                                    }
                                
                                    return 0;
                                }                                
                        
                    

Write a C++ program to merge two arrays into the second array:


                        
                            #include<iostream>
                                using namespace std;
                                int main()
                                { 
                                
                                    int size1;
                                    int size2;
                                    int size3;
                                    cout<<"Enter the size of the first array:"<<endl;
                                    cin>>size1;
                                    int arr1[size1];
                                    cout<<"Enter the elements of one array:"<<endl;
                                    for(int i=0;i<size1;i++){
                                        cin>>arr1[i];
                                    }
                                    cout<<"Enter the size of the first array:"<<endl;
                                    cin>>size2;
                                    int arr2[size2];
                                    cout<<"Enter the elements in the second array:"<<endl;
                                    for(int i=0;i<size2;i++){
                                        cin>>arr2[i];
                                    }
                                    size3=size1+size2;
                                    int arr3[size3]={};
                                    cout<<"The third array before the merging is initialized to zero as:"<<endl;
                                    for(int i=0;i<size3;i++){
                                        cout<<arr3[i]<<" ";
                                    }
                                    cout<<endl;
                                    int j=0;
                                    for(int i=0;i<size3;i++){
                                        if(i<size1)
                                        {
                                            arr3[i]=arr1[i];
                                        }
                                        else{
                                            arr3[i]=arr2[j];
                                            j++;
                                        }
                                
                                    }
                                 cout<<"The third array after the merging is as:"<<endl;
                                 for(int i=0;i<size3;i++)
                                 {
                                     cout<<arr3[i]<<" ";
                                 }
                                   return 0;
                                
                                }                                
                        
                    

Write a C++ program to revers the array:


                        
                            #include<iostream>
                                #include<cstdlib>
                                #include<ctime>
                                using namespace std;
                                int main()
                                {
                                   const int size=10;
                                   int x=time(0);
                                   srand(x);
                                   int arr[size];
                                   cout<<"The array without reversed as:"<<endl;
                                   for(int i=0;i<size;i++){
                                       arr[i]=(rand()%10)+1;
                                   }
                                   for(int i=0;i<size;i++){
                                       cout<<arr[i]<<" ";
                                   }
                                   cout<<endl;
                                   for(int i=0,j=size-1;i<(size/2);i++,j--){
                                        int temp;
                                        temp=arr[i];
                                        arr[i]=arr[j];
                                        arr[j]=temp;
                                   }
                                   cout<<"The reversed array is as:"<<endl;
                                   for(int i=0;i<size;i++){
                                       cout<<arr[i]<<" ";
                                   }
                                    return 0;
                                }
                        
                    

Write a C++ program to put the even and odd elements of an array into the two separate arrays:


                        
                            #include<iostream>
                                using namespace std;
                                int main()
                                {
                                   const int size=10;
                                   int arr3[size];
                                   int arr_even[size]={};
                                   int arr_odd[size]={};
                                   int even=0;
                                   int odd=0;
                                   cout<<"Enter the elements in the array:"<<endl;
                                   for(int i=0;i<size;i++)
                                   {
                                       cin>>arr3[i];
                                   }
                                   cout<<"The elements enter in the array are :"<<endl;
                                   for(int i=0;i<size;i++)
                                   {
                                       cout<<arr3[i]<<" ";
                                   }
                                   cout<<endl;
                                   for(int i=0,j=0,k=0;i<size;i++)
                                   {
                                       if(arr3[i]%2==0){
                                           arr_even[j]=arr3[i];
                                           even++;
                                           j++;
                                       }
                                       else
                                       {
                                           arr_odd[k]=arr3[i];
                                           odd++;
                                           k++;
                                       }
                                   }
                                   cout<<"The even elements in the array are as:"<<endl;
                                   for(int i=0;i<even;i++){
                                       cout<<arr_even[i]<<" ";
                                   }
                                   cout<<endl;
                                    cout<<"The odd elements in the array are as:"<<endl;
                                   for(int i=0;i<odd;i++){
                                       cout<<arr_odd[i]<<" ";
                                   }  
                                    return 0;
                                }                                
                        
                    

Sorting Alhorithms:

Bubble Sort


                        
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
    int x = time(0);
    srand(x);
    int size = 10;
    int arr[size];
    cout << "The elemnets in the array are given as:" << endl;
    for (int i = 0; i < size; i++)
    {
        // arr[i] = (rand() % 20) + 1;
        cin>>arr[i];
    }
    for (int i = 0; i < size; i++)
    {
        cout << arr[i] << " ";
    }
    cout << endl;
    int innerSize=size;
    cout << "The sorted array in the asscending order is given as as:" << endl;
    for (int i = 0; i < size; i++)
    {
        for (int j = 0; j < innerSize; j++)
        {
            int temp = arr[j + 1];
            if (arr[j] > arr[j + 1])
            {
                arr[j + 1] = arr[j];
                arr[j] = temp;
            }
        }
        innerSize--;
    }
    for (int i = 0; i < size; i++)
    {
        cout << arr[i] << " ";
    }
    cout << endl;
    // cout << sizeof(arr) / sizeof(int); // To check the size of the array that can be given in the array:

    return 0;
}
                        
                    

Selection Sort


                        
                           #include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
    int size = 10;
    int x = time(0);
    srand(x);
    int arr[size] = {};
    int min_index;
    for (int i = 0; i < size; i++)
    {
        arr[i] = (rand() % 20) + 1;
    }
    for (int i = 0; i < size; i++)
    {
        cout << arr[i] << " ";
    }
    for (int i = 0; i < size - 1; i++)
    {
        min_index = i;
        for (int j = i + 1; j < size; j++)
        {
            if (arr[j] < arr[min_index])
            {
                min_index = j;
            }
        }
        int temp;
        temp = arr[i];
        arr[i] = arr[min_index];
        arr[min_index] = temp;
    }
    cout << endl;
    for (int i = 0; i < size; i++)
    {
        cout << arr[i] << " ";
    }
    return 0;
}
                        
                    

Insertion Sort


                        
                           #include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
    int x = time(0);
    srand(x);
    const int size = 10;
    int arr[size];
    for (int i = 0; i < size; i++)
    {
        arr[i] = (rand() % 10) + 1;
    }
    for (int i = 0; i < size; i++)
    {
        cout << arr[i] << " ";
    }
    for (int i = 1; i < size; i++)
    {
        int temp;
        if (arr[i] < arr[i - 1])
        {
            temp = arr[i];
            int j = i;
            do
            {
                arr[j] = arr[j - 1];
                j--;
            } while (j > 0 && arr[j - 1] > temp);
            arr[j] = temp;
        }
    }
    cout << endl;
    for (int i = 0; i < size; i++)
    {
        cout << arr[i] << " ";
    }

    return 0;
}
                        
                    

>2D-Arrays

Write a program to add two matrixes.


                        
#include<iostream>
#include<cstdlib>
#include<ctime>
#include<iomanip>
using namespace std;
int main()
{
    int x=time(0);
    srand(x);
    const int row=5;
    const int col=4;
    int arr2d[row][col];
    int arr2d1[row][col];
    int sum[row][col];
    int sum1;
    for(int i=0;i<row;i++)
    {
        for(int j=0;j<col;j++){
            arr2d[i][j]=(rand()%9)+1;
        }
    }
    for(int i=0;i<row;i++)
    {
        for(int j=0;j<col;j++){
            arr2d1[i][j]=(rand()%9)+1;
        }
    }
    for(int i=0;i<row;i++)
    {
        cout<<left;
        for(int j=0;j<col;j++){
            cout<<setw(5)<<arr2d[i][j];
        }
        cout<<endl;
    }
    cout<<endl;
    cout<<endl;
    for(int i=0;i<row;i++)
    {
        cout<<left;
        for(int j=0;j<col;j++){
            cout<<setw(5)<<arr2d1[i][j];
        }
        cout<<endl;
    }
    cout<<endl;
    cout<<endl;
    for(int i=0;i<row;i++)
    {
        for(int j=0;j<col;j++)
        {
            sum1=arr2d[i][j]+arr2d1[i][j];
            sum[i][j]=sum1;
        }
        cout<<endl;
    }

    for(int i=0;i<row;i++)
    {
        for(int j=0;j<col;j++)
        {
            cout<<left;
            cout<<setw(5)<<arr2d[i][j];
        }
        if(i!=2)
        {
            cout<<"     ";
        }
        else if(i==2)
        {
            cout<<"+    ";
        }
         for(int j=0;j<col;j++)
        {
            cout<<left;
            cout<<setw(5)<<arr2d1[i][j];
        }
       if(i!=2)
        {
            cout<<"     ";
        }
        else if(i==2)
        {
            cout<<"=    ";
        }
        for(int j=0;j<col;j++)
        {
            cout<<left;
            cout<<setw(7)<<sum[i][j];
        }
        cout<<endl;
        
    }

    

    return 0;
}
                        
                    

Write a C++ program to find the daigonal sum of the matrix.


                        
                            #include<iostream>
#include<iomanip>
#include<ctime>
#include<cstdlib>
using namespace std;
int main()
{
    const int row=4;
    const int col=5;
    int sum=0;
    int board[row][col];
    for(int i=0;i<row;i++)
    {
        for(int j=0;j<col;j++)
        {
            board[i][j]=(rand()%9)+1;
        }
    }
    for(int i=0;i<row;i++)
    {
        for(int j=0;j<col;j++)
        {
            cout<<left;
            cout<<setw(5)<<board[i][j]<<" ";
        }
        cout<<endl;
    }
    cout<<"The diagonal sum is :"<<endl;
    for(int i=0;i<row;i++)
    {
        sum+=board[i][i];
    }
    cout<<sum;

    return 0;
}
                        
                    

Write a C++ Program to find the determinent of a 3x3 by matrix.


                        
#include<iostream>
#include<ctime>
#include<cstdlib>
#include<iomanip>
using namespace std;
int main()
{
  const int row=3;
  const int col=3;
  int x=time(0);
  srand(x);
  int deter=0;
  int a,b,c;
  int board[row][col];
  for(int i=0;i<row;i++)
  {
      for(int j=0;j<col;j++)
      {
        //   board[i][j]=(rand()%9)+1;
        cin>>board[i][j];
      }
  }
  for(int i=0;i<row;i++)
  {
      for(int j=0;j<col;j++)
      {
          cout<<left;
         cout<<setw(6)<<board[i][j]<<" ";
      }
      cout<<endl;
  }
  //for the 2x2 board
  if(row==2 && col==2)
  {
  deter=(board[0][0]*board[1][1])-(board[0][1]*board[1][0]);
  cout<<"The determinent = "<<deter<<endl;
  }
  //for the 3x3
  if(row==3 && col==3){
    a=(board[1][1]*board[2][2])-(board[1][2]*board[2][1]);
    b=(board[1][0]*board[2][2])-(board[1][2]*board[2][0]);
    c=(board[1][0]*board[2][1])-(board[1][1]*board[2][0]);
    deter=(board[0][0]*a)-(board[0][1]*b)+(board[0][2]*c);
    cout<<"The determinent = "<<deter<<endl;
  }
  else
  {
      cout<<"We are working on it please wait till:"<<endl;
  }




    return 0;
}
                        
                    

Write a C++ program for the diagonal interchange.


                        
#include<iostream>
#include<iomanip>
#include<ctime>
#include<cstdlib>
using namespace std;
int main()
{
    const int row=5;
    const int col=5;
    int board[row][col];
    for(int i=0;i<row;i++)
    {
        for(int j=0;j<col;j++)
        {
            board[i][j]=(rand()%9)+1;
        }
    }
    for(int i=0;i<row;i++)
    {
        for(int j=0;j<col;j++)
        {
            cout<<left;
            cout<<setw(5)<<board[i][j]<<" ";
        }
        cout<<endl;
    }
    for(int i=0,j=row-1;i<row && j>=0;i++,j--)
    {
        int temp;
        temp=board[i][i];
        board[i][i]=board[i][j];
        board[i][j]=temp;
    }
    cout<<endl;
    cout<<"The interchanged board :"<<endl;
    cout<<endl;
     for(int i=0;i<row;i++)
    {
        for(int j=0;j<col;j++)
        {
            cout<<left;
            cout<<setw(5)<<board[i][j]<<" ";
        }
        cout<<endl;
    }


    return 0;
}
                        
                    

Write a C++ progarm to find the given matrix is equal matrix or not


                        
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
    int r1,c1,r2,c2;
    bool flag=true;
    cout<<"Enter the row of board 1:"<<endl;
    cin>>r1;
    cout<<"Enter the column of board 1:"<<endl;
    cin>>c1;
    cout<<"Enter the row of board 2:"<<endl;
    cin>>r2;
    cout<<"Enter the column of board 2:"<<endl;
    cin>>c2;
    int board1[r1][c1];
    int board2[r2][c2];
    cout<<"Enter the board 1:"<<endl;
    for(int i=0;i<r1;i++)
    {
        for(int j=0;j<c1;j++)
        {
            cin>>board1[i][j];
        }
    }
    cout<<"Enter the board 2:"<<endl;
    for(int i=0;i<r2;i++)
    {
        for(int j=0;j<c2;j++)
        {
            cin>>board2[i][j];
        }
    }
    cout<<"board 1 is as:"<<endl;
     for(int i=0;i<r1;i++)
    {
        for(int j=0;j<c1;j++)
        {
            cout<<left;
            cout<<setw(5)<<board1[i][j]<<" ";
        }
        cout<<endl;
    }
    cout<<"board 2 is as:"<<endl;
     for(int i=0;i<r2;i++)
    {
        for(int j=0;j<c2;j++)
        {
            cout<<left;
            cout<<setw(5)<<board2[i][j]<<" ";
        }
        cout<<endl;
    }
    //comparing
    if(r1!=r2 || c1!=c2)
    {
        cout<<"Both boardes are unequal:"<<endl;
    }
    else
    {
        for(int i=0;i<r1;i++)
        {
            for(int j=0;j<c1;j++)
            {
                if(board1[i][j]!=board2[i][j])
                {
                    flag=false;
                }
            }
        }
        if(flag==false)
        {
            cout<<"Both boardes are unequal:"<<endl;
        }
        if(flag==true)
        {
            cout<<"Both boardes are equal:"<<endl;
        }
    }

    return 0;
}
                        
                    

Write a C++ program to check the given matrix is identity matrix or not.


                        
#include<iostream>
#include<ctime>
#include<cstdlib>
#include<iomanip>
using namespace std;
int main()
{
  const int row=3;
  const int col=3;
  int x=time(0);
  srand(x);
  bool flag =true;
  int board[row][col];
  for(int i=0;i<row;i++)
  {
      for(int j=0;j<col;j++)
      {
        //   board[i][j]=(rand()%9)+1;
        cin>>board[i][j];
      }
  }
  for(int i=0;i<row;i++)
  {
      for(int j=0;j<col;j++)
      {
          cout<<left;
         cout<<setw(6)<<board[i][j]<<" ";
      }
      cout<<endl;
  }
  for(int i=0;i<row;i++)
  {
      if(board[i][i]!=1)
      {
          flag=false;
      }
      for(int j=i+1;j<col;j++)
      {
          if(board[i][j]!=0)
          {
              flag=false;
          }
      }
  }
  for(int i=1;i<row;i++)
  {
      for(int j=0;j<i;j++)
      {
         if(board[i][j]!=0)
         {
             flag=false;
         }
      }
  }
  if(flag==false)
  {
      cout<<"It is not an identity board:"<<endl;
  }
  if(flag==true)
  {
      cout<<"It is  an identity board:"<<endl;
  }
  return 0;
}
                        
                    

Write a C++ progarm to check given matrix is lower traingular matrix or not.


                        
#include<iostream>
#include<iomanip>
#include<ctime>
#include<cstdlib>
using namespace std;
int main()
{
    const int row=3;
    const int col=3;
    bool flag=true;
    int board[row][col];
    for(int i=0;i<row;i++)
    {
        for(int j=0;j<col;j++)
        {
            // board[i][j]=(rand()%9)+1;
            cin>>board[i][j];
        }
    }
    for(int i=0;i<row;i++)
    {
        for(int j=0;j<col;j++)
        {
            cout<<left;
            cout<<setw(5)<<board[i][j]<<" ";
        }
        cout<<endl;
    }
    for(int i=0;i<row;i++)
    {
        for(int j=i+1;j<row;j++)
        {
            if(board[i][j]!=0)
            {
                flag=false;
            }
        }
    }
    if(flag==false)
    {
        cout<<"It is not an lower triangular board:"<<endl;
    }
    if(flag==true)
    {
        cout<<"It is an lower triangular board:"<<endl;
    }


    return 0;
}
                        
                    

Write a C++ Progarm to find out the minor diagonal sum of the matrix.


                        
#include<iostream>
#include<iomanip>
#include<ctime>
#include<cstdlib>
using namespace std;
int main()
{
    const int row=3;
    const int col=3;
    int sum=0;
    int board[row][col];
    for(int i=0;i<row;i++)
    {
        for(int j=0;j<col;j++)
        {
            board[i][j]=(rand()%9)+1;
        }
    }
    for(int i=0;i<row;i++)
    {
        for(int j=0;j<col;j++)
        {
            cout<<left;
            cout<<setw(5)<<board[i][j]<<" ";
        }
        cout<<endl;
    }
    cout<<"The minor diagonal sum is :"<<endl;
    for(int i=row-1,j=0;i>=0 && j<row;i--,j++)
    {
        sum+=board[j][i];
    }
    cout<<sum;

    return 0;
}
                        
                    

Write a C++ program to Multiply two matrixes.


                        
#include<iostream>
#include<cstdlib>
#include<ctime>
#include<iomanip>
using namespace std;
int main()
{
    int x=time(0);
    srand(x);
    int r1,c1;
    int r2,c2;
    int multi1,multi2;
    cout<<"Enter the number of rows of first board:"<<endl;
    cin>>r1;
    cout<<"Enter the number of columns of first board:"<<endl;
    cin>>c1;
    cout<<"Enter the number of rows of secind board:"<<endl;
    cin>>r2;
    cout<<"Enter the number of columns of secind board:"<<endl;
    cin>>c2;
    /*It is must that the number of columns of first board 
    is equal to the number of rows of second board*/
    while(c1!=r2)
    {
        cout<<"Invalid input!"<<endl;
    cout<<"Again Enter "<<endl;
    cout<<"Enter the number of rows of first board:"<<endl;
    cin>>r1;
    cout<<"Enter the number of columns of first board:"<<endl;
    cin>>c1;
    cout<<"Enter the number of rows of secind board:"<<endl;
    cin>>r2;
    cout<<"Enter the number of columns of secind board:"<<endl;
    cin>>c2;
    }
    int board1[r1][c1];
    int board2[r2][c2];
    /*Resultant board has number of rows equal to the board_1 rows
    And number of columns equal to the board_2 columns*/
    int multi[r1][c2]={0};
    //Input for the board 1
    for(int i=0;i<r1;i++)
    {
        for(int j=0;j<c1;j++)
        {
            // board1[i][j]=(rand()%9)+1;
            cin>>board1[i][j];
        }
    }
    //Display board 1
     //Display
     cout<<"board 1 :"<<endl; 
    for(int i=0;i<r1;i++)
    {
        for(int j=0;j<c1;j++)
        {
            cout<<left;
            cout<<setw(5)<<board1[i][j];
        }
        cout<<endl;
    }
    cout<<endl;
    //Input for the board-2
    for(int i=0;i<r2;i++)
    {
        for(int j=0;j<c2;j++)
        {
            // board2[i][j]=(rand()%9)+1;
            cin>>board2[i][j];
        }
    }
    //Display board 2
    cout<<"board 2:"<<endl; 
    for(int i=0;i<r2;i++)
    {
        for(int j=0;j<c2;j++)
        {
            cout<<left;
            cout<<setw(5)<<board2[i][j];
        }
        cout<<endl;
    }
    cout<<endl;
    //multiplication of board 1 with board 2
    for(int i=0;i<r1;i++)
    {
        for(int j=0;j<c2;j++)
        {
            for(int k=0;k<c1;k++)
            {
                multi[i][j]+=board1[i][k]*board2[k][j];
            }
        }
    }
    //Display multiplication
    cout<<"Multiplication board1*board2:"<<endl;
    for(int i=0;i<r1;i++)
    {
        for(int j=0;j<c2;j++)
        {
            cout<<left;
            cout<<setw(5)<<multi[i][j];
        }
        cout<<endl;
    }

    return 0;
}
                        
                    

Write a C++ Program to check the given marix is scalar or not.


                        
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <iomanip>
using namespace std;
int main()
{
    const int row = 5;
    const int col = 5;
    int arr[row][col];
    int num;
    for (int i = 0; i < row; i++)
    {
        for (int j = 0; j < col; j++)
        {
            arr[i][j] = rand() % 9;
        }
    }
    cout << "The board is given as:" << endl;
    for (int i = 0; i < row; i++)
    {
        cout << left;
        for (int j = 0; j < col; j++)
        {
            cout << setw(5) << arr[i][j];
        }
        cout << endl;
    }
    cout << endl;
    cout << "Enter the number that you want to multiplay:" << endl;
    cin >> num;

    cout << endl;
    for (int i = 0; i < row; i++)
    {
        cout << left;
        for (int j = 0; j < col; j++)
        {
            cout << setw(5) << (num * arr[i][j]);
        }
        cout << endl;
    }

    return 0;
}
                        
                    

Write a C++ program to check whether the given matrix is upper traingular matrix or not.


                        
#include<iostream>
#include<iomanip>
#include<ctime>
#include<cstdlib>
using namespace std;
int main()
{
    const int row=3;
    const int col=3;
    bool flag=true;
    int board[row][col];
    for(int i=0;i<row;i++)
    {
        for(int j=0;j<col;j++)
        {
            // board[i][j]=(rand()%9)+1;
            cin>>board[i][j];
        }
    }
    for(int i=0;i<row;i++)
    {
        for(int j=0;j<col;j++)
        {
            cout<<left;
            cout<<setw(5)<<board[i][j]<<" ";
        }
        cout<<endl;
    }
    for(int i=1;i<row;i++)
    {
        for(int j=0;j<i;j++)
        {
            if(board[i][j]!=0)
            {
                flag=false;
            }
        }
    }
    if(flag==false)
    {
        cout<<"It is not an upper triangular board:"<<endl;
    }
    if(flag==true)
    {
        cout<<"It is an upper triangular board:"<<endl;
    }


    return 0;
}
                        
                    

Write a C++ program to find the transpose of a matrix.


                        
                            #include<iostream>
#include<iomanip>
#include<ctime>
#include<cstdlib>
using namespace std;
int main()
{
    const int row=4;
    const int col=6;
    int board[row][col];
    int sum=0;
    for(int i=0;i<row;i++)
    {
        for(int j=0;j<col;j++)
        {
            board[i][j]=(rand()%9)+1;
            // cin>>board[i][j];
        }
    }
    for(int i=0;i<row;i++)
    {
        for(int j=0;j<col;j++)
        {
            cout<<left;
            cout<<setw(5)<<board[i][j]<<" ";
        }
        cout<<endl;
    }

    cout<<"The transpose of the board :"<<endl;
    for(int i=0;i<col;i++)
    {
        for(int j=0;j<row;j++)
        {
        cout<<left;
        cout<<setw(5)<<board[j][i]<<" ";           
        } 
        cout<<endl;
    }
    


    return 0;
}
                        
                    

Write a C++ program to find the sum of the upper traingular matrix.


                        
                            #include<iostream>
#include<iomanip>
#include<ctime>
#include<cstdlib>
using namespace std;
int main()
{
    const int row=3;
    const int col=3;
    int board[row][col];
    int sum=0;
    for(int i=0;i<row;i++)
    {
        for(int j=0;j<col;j++)
        {
            // board[i][j]=(rand()%9)+1;
            cin>>board[i][j];
        }
    }
    for(int i=0;i<row;i++)
    {
        for(int j=0;j<col;j++)
        {
            cout<<left;
            cout<<setw(5)<<board[i][j]<<" ";
        }
        cout<<endl;
    }

    cout<<"The sum of the upper traingle board :"<<endl;
    for(int i=0;i<row;i++)
    {
      for(int j=i+1;j<col;j++)
      {
          sum+=board[i][j];
      }
    }
    cout<<sum;


    return 0;
}
                        
                    

Write a C++ program to find the sum of the lower traingular matrix.


                        
                           #include<iostream>
#include<iomanip>
#include<ctime>
#include<cstdlib>
using namespace std;
int main()
{
    const int row=3;
    const int col=3;
    int board[row][col];
    int sum=0;
    for(int i=0;i<row;i++)
    {
        for(int j=0;j<col;j++)
        {
            // board[i][j]=(rand()%9)+1;
            cin>>board[i][j];
        }
    }
    for(int i=0;i<row;i++)
    {
        for(int j=0;j<col;j++)
        {
            cout<<left;
            cout<<setw(5)<<board[i][j]<<" ";
        }
        cout<<endl;
    }

    cout<<"The sum of the upper traingle board :"<<endl;
    for(int i=1;i<row;i++)
    {
      for(int j=i-1;j>=0;j--)
      {
          sum+=board[i][j];
      }
    }
    cout<<sum;


    return 0;
}
                        
                    

3D-Arrays

Initalization and printing


                        
#include<iostream>
#include<iomanip>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
    int x=time(0);
    srand(x);
    const int row=10;
    const int col=10;
    const int z=10;
    int three_D[row][col][z];
    //input
    for(int k=0;k<z;k++)
    {
        for(int i=0;i<row;i++)
        {
            for(int j=0;j<col;j++)
            {
                three_D[i][j][k]=(rand()%9)+1;
                // cin>>three_D[i][j][k];
            }
        }
    }
 //output
     for(int k=0;k<z;k++)
    {
        cout<<"Matrix "<<k+1<<" :"<<endl;
        for(int i=0;i<row;i++)
        {
            for(int j=0;j<col;j++)
            {
                cout<<left;
                cout<<setw(5)<<three_D[i][j][k]<<" ";
            }
            cout<<endl;
        }
        cout<<endl;
        cout<<endl;
    }
    return 0;
}
                    </code></pre>
            </div>
        </div>
    </div>





   <h1  id="under-commands">Character Arrays</h1>



    <div class="col-6">
        <div class="row-6-1">
            <h2>Wrire a C++ Program to find the Vowels,Cononants,Symbols ,numbers in the array.</h2>
            <div class="code18">
                <pre><code class="language-cpp">
                        <xmp>
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
    int size=100;
    char ch[size];
    cin.getline(ch,size);
    int alphabtes;
    int symboles;
    int numbers;
    int vowels;
    int consonants;
    for(int i=0;ch[i]!='\0';i++)
    {
        if((ch[i]>='a' && ch[i]<='z') ||(ch[i]>='A'&&ch[i]<='Z'))
        {
           alphabtes++;
        }
        else if(ch[i]>='0' && ch[i]<='9')
        {
            numbers++;
        }
        else
        {
            symboles++;
        }
        if(ch[i]=='a'|| ch[i]=='i'||ch[i]=='e'||ch[i]=='o'||ch[i]=='u')
        {
          vowels++;
        }
        else
        {
            consonants++;
        }
    }
    cout<<alphabtes<<endl;
    cout<<numbers<<endl;
    cout<<symboles<<endl;
    cout<<vowels<<endl;
    cout<<consonants-symboles-numbers<<endl;
    
    return 0;
}
                        
                    

Write a C++ program in character array to find out which charracter string is greater(Comparing of two strings).


                        
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
    //it is basically works on the ascii values
    int size=100;
    char ch1[size];
    char ch2[size];
    int result;
    cin.getline(ch1,size);
    cin.getline(ch2,size);
   result= strcmp(ch1,ch2);
   switch(result)
   {
       case -1:
       {
           cout<<ch2<<" is greater than "<<ch1<<endl;
           break;
       }
       case 1:
       {
           cout<<ch1<<" is greater than "<<ch2<<endl;
           break;
       }
      case 0:
       {
           cout<<ch1<<" and "<<ch1<<" both are equal to each other."<<endl;
           break;
       } 
   }
    return 0;
}
                        
                    

Concatination of two character strings


                        
                           #include<iostream>
                               #include<cstring>
                                   using namespace std;
                                   int main()
                                   {
                                   int size=100;
                                   char ch1[size];
                                   char ch2[size];
                                   cin.getline(ch1,size);
                                   cin.getline(ch2,size);
                                   strcat(ch1,ch2);
                                   strncat(ch1,ch2,5);
                                   strcat(ch1,"Muhib");
                                   cout<<ch1; return 0; }
                        
                    

C++ progarm to copy one character string into another (methods)


                        
                            #include<iostream>
                                #include<cstring>
                                    using namespace std;
                                    int main()
                                    {
                                    int size=100;
                                    char arr1[size];
                                    char arr2[size];
                                    cin.getline(arr1,size);
                                    cin.getline(arr2,size);
                                    strcpy(arr1,arr2);
                                    strncpy(arr1,arr2,5);
                                    strcpy(arr1,"Muhib Arshad");
                                    cout<<arr1; return 0; }



                                    //Copy with the for loop



                                    #include<iostream>
                                        #include<cstring>
                                            using namespace std;
                                            int main()
                                            {
                                            int size=100;
                                            char arr1[size];
                                            char arr2[size];
                                            cin.getline(arr1,size);
                                            cin.getline(arr2,size);
                                            for(int i=0;arr2[i]!='\0';i++)
                                            {
                                            arr1[i]=arr2[i];
                                            }
                                            cout<<arr1; return 0; }
                        
                    

Write a C++ progarm to find out how many times the given word is repeated in the character string.


                        
#include<iostream>
using namespace std;
int main()
{
    int size=100;
    char ch[size];
    char se;
    int count=0;
    cin.getline(ch,size);
    cout<<"Enter the  count character :"<<endl;
    cin>>se;
    for(int i=0;ch[i]!='\0';i++)
    {
        if(ch[i]==se)
        {
           count++;
        }
    }
    cout<<se<<" count is "<<count<<endl;

    return 0;
}

                        
                    

Write a C++ program to find index at which the first occurance of a letter in a string


                        
                            #include<iostream>
                                using namespace std;
                                int main()
                                {
                                int size=100;
                                char ch[size];
                                char se;
                                int index;
                                cin.getline(ch,size);
                                cout<<"Enter the first occurance character :"<<endl; cin>>se;
                                    bool flag =false;
                                    for(int i=0;ch[i]!='\0' && flag==true;i++)
                                    {
                                    if(ch[i]==se)
                                    {
                                    index=i;
                                    flag=true;
                                    }
                                    }
                                    cout<<"The character "<<se<<" firstly occures at the "<<index<<" index :"<<endl; }

                        
                    

Write a C++ program to find the occurance of each letter in a sentence.


                        
#include<iostream>
using namespace std;
int main()
{
    const int size=100;
    char ch[size];
    int arr[size]={0};
    int count=0;
    int index=0;
    int max;
    cout<<"Eneter the character string:"<<endl;
    cin.getline(ch,size);
    for(int i=0;ch[i]!='\0';i++)
    {
        count=1;
        for(int j=i+1;ch[j]!='\0';j++)
        {
           if(ch[i]==ch[j])
           {
               count++;
               arr[j]=-1;
           }
        }
        if(arr[i]!=-1)
        {
            arr[i]=count;
        }
    }
    max=arr[0];
    for(int i=0;ch[i]!='\0';i++)
    {
     if(arr[i]!=-1)
     {
         cout<<ch[i]<<" is repeated "<<arr[i]<<" times "<<endl;
     }
    }

    return 0;
}

                    

Write a C++ prorgram to find the highest frequency of a letter in a character string.


                        
                            #include<iostream>
                                using namespace std;
                                int main()
                                {
                                const int size=100;
                                char ch[size];
                                int arr[size]={0};
                                int count=0;
                                int index=0;
                                int max;
                                cout<<"Eneter the character string:"<<endl; cin.getline(ch,size); for(int
                                    i=0;ch[i]!='\0' ;i++) { count=1; for(int j=i+1;ch[j]!='\0' ;j++) { if(ch[i]==ch[j])
                                    { count++; arr[j]=-1; } } if(arr[i]!=-1) { arr[i]=count; } } max=arr[0]; for(int
                                    i=0;i<size;i++) { if(arr[i]>max)
                                    {
                                    max=arr[i];
                                    index=i;
                                    }
                                    }
                                    cout<<"The highest frequency of the character in the string is "<<ch[index]<<endl;

    return 0;
}
                        
                    

Write a C++ program to find the at which last index the given letter exist in a character string.


                        
                            #include<iostream>
using namespace std;
int main()
{
    int size=100;
    char ch[size];
    char se;
    int index;
    cin.getline(ch,size);
    cout<<"Enter the  occurance character :"<<endl;
    cin>>se;
    cout<<"The character "<<se<<"  occures at the ";
    for(int i=0;ch[i]!='\0';i++)
    {
        if(ch[i]==se)
        {
            index=i;
            cout<<index<<" index : and";
        }
    }

    return 0;
}

                        
                    

Write a C++ program to remove the given letter at ist last occurance in a character string.


                        
                            #include <iostream>
                                using namespace std;
                                int main()
                                {
                                int size = 100;
                                char ch[size];
                                char toremove;
                                cin.getline(ch, size);
                                for (int i = 0; ch[i] != '\0'; i++)
                                {
                                if (isupper(ch[i]))
                                {
                                ch[i] = tolower(ch[i]);
                                }
                                }
                                int index = 0;
                                cout << "Enter the character that you want to remove its first occurance:" << endl; cin>
                                    > toremove;
                                    toremove = tolower(toremove);
                                    cin.ignore();
                                    for (int i = 0; ch[i] != '\0'; i++)
                                    {
                                    if (ch[i] == toremove)
                                    {
                                    index = i;
                                    }
                                    }
                                    for (int j = index; ch[j + 1] != '\0'; j++)
                                    {
                                    ch[j] = ch[j + 1];
                                    }
                                    for (int i = 0; ch[i + 1] != '\0'; i++)
                                    {
                                    cout << ch[i]; } return 0; }
                        
                    

Write a C++ program to find the length of a string.


                        
                           #include<iostream>
                               using namespace std;
                               int main()
                               {
                               int size;
                               cin>>size;
                               cin.ignore();
                               char ch[size];
                               cin.getline(ch,size);
                               int count=0;
                               for(int i=0;ch[i]!='\0';i++){
                               count++;
                               }
                               cout<<count<<" ";


    return 0;
}
                        
                    

Write a C++ program to convert the all lowerCase letters to Uppercase letters.


                        
                            #include<iostream>
#include<cstring>
using namespace std;
int main()
{
    //it is basically works on the ascii values
    int size=100;
    char ch1[size];
    cin.getline(ch1,size);
    for(int i=0;i<size;i++)
    {
      if(islower(ch1[i]))
      {
        ch1[i]=toupper(ch1[i]);
      }
    }
    cout<<ch1;
    return 0;
}
                        
                    

Write a C++ program to find the lowest occurance of a letter in a character string.


                        
                            #include<iostream>
using namespace std;
int main()
{
    const int size=100;
    char ch[size];
    int arr[size]={0};
    int count=0;
    int index=0;
    int min;
    int lowest[size]={};
    cout<<"Eneter the character string:"<<endl;
    cin.getline(ch,size);
    for(int i=0;ch[i]!='\0';i++)
    {
        count=1;
        for(int j=i+1;ch[j]!='\0';j++)
        {
           if(ch[i]==ch[j])
           {
               count++;
               arr[j]=2;
           }
        }
        if(arr[i]!=2)
        {
            arr[i]=count;
        }
    }
    min=arr[0];
    for(int i=0;i<size;i++)
    {
     if(arr[i]==1)
     {
       lowest[i]=ch[i];  
     }
     }
    
    cout<<"The lowest frequency characters in the string is ";
    for(int i=0;i<sizeof(lowest)/sizeof(int);i++)
    {
     if(lowest[i]!=0)
     {
      cout<<char(lowest[i])<<" ";
     }
    }

    return 0;
}
                        
                    

Write a C++ program to find out given word is palindrome or not.


                        
                            #include<iostream>
#include<cstring>
using namespace std;
int main()
{
    int size=100;
    char ch[size];
    cin.getline(ch,size);
    int length=strlen(ch)-1;
    bool flag =true;
    int k=0;
    while(ch[k]!='\0')
    {
        ch[k]=tolower(ch[k]);
        k++;
    }
    for(int i=0,j=length;ch[i]!='\0';i++,j--)
    {
       if(ch[i]!=ch[j])
       {
          flag=false;
       }
    }
    if(flag==false)
    {
        cout<<"It is not a palindrome!"<<endl;
    }
    if(flag==true)
    {
        cout<<"It is a palindrome!"<<endl;
    }    
    return 0;
}
                        
                    

Write a C++ program to remove the fist occurance of a letter at index.


                        
                            #include<iostream>
                                using namespace std;
                                int main()
                                {
                                int size=100;
                                char ch[size];
                                char toremove;
                                cin.getline(ch,size);
                                for(int i=0;ch[i]!='\0';i++)
                                {
                                if(isupper(ch[i]))
                                {
                                ch[i]=tolower(ch[i]);
                                }
                                }
                                bool flag=false;
                                cout<<"Enter the character that you want to remove its first occurance:"<<endl; cin>
                                    >toremove;
                                    toremove=tolower(toremove);
                                    cin.ignore();
                                    for(int i=0;(ch[i]!='\0') && flag==false;i++)
                                    {
                                    if(ch[i]==toremove)
                                    {
                                    for(int j=i;ch[j+1]!='\0';j++)
                                    {
                                    ch[j]=ch[j+1];
                                    }
                                    flag=true;
                                    }
                                    }
                                    for(int i=0;ch[i+1]!='\0';i++)
                                    {
                                    cout<<ch[i]; } return 0; }
                        
                    

Write a C++ program to reverse the given character string.


                        
                           #include<iostream>
                               #include<cstring>
                                   using namespace std;
                                   int main()
                                   {
                                   int size=100;
                                   char ch[size];
                                   char reverse[size];
                                   int x;
                                   cin.getline(ch,size);
                                   x=strlen(ch);
                                   int i=0,j=x-1;
                                   while(ch[i]!='\0')
                                   {
                                   reverse[i]=ch[j];
                                   i++;
                                   j--;
                                   }
                                   cout<<reverse; return 0; }
                        
                    

Write a C++ program to convert all the letters of the character string into the toggle case.


                        
                            #include<iostream>
                                #include<cstring>
                                    using namespace std;
                                    int main()
                                    {
                                    int size=100;
                                    char ch[size];
                                    int count=0;
                                    cin.getline(ch,size);
                                    for(int i=0;ch[i]!='\0';i++)
                                    {
                                    if(islower(ch[i]))
                                    {
                                    ch[i]=toupper(ch[i]);
                                    }
                                    else if(isupper(ch[i]))
                                    {
                                    ch[i]=tolower(ch[i]);
                                    }
                                    }
                                    cout<<ch; return 0; }
                        
                    

Write a C++ program to find the total letters in the character string.


                        
                           #include<iostream>
                               #include<cstring>
                                   using namespace std;
                                   int main()
                                   {
                                   int size=100;
                                   char ch[size];
                                   cin.getline(ch,size);
                                   int count=0;
                                   for(int i=0;ch[i]!='\0';i++)
                                   {
                                   if(ch[i]==' ')
                                   {
                                   count++;
                                   }
                                   }
                                   cout<<count+1<<endl; return 0; }
                        
                    

Write a C++ Program to revres the words in the string.


                        
                           #include <iostream>
                               #include <cstring>
                                   using namespace std;
                                   int main()
                                   {
                                   int size = 100;
                                   char ch[size];
                                   char reverse[size];
                                   int x;
                                   int length;
                                   cin.getline(ch, size);
                                   x = strlen(ch);
                                   length = x - 1;//get lenghth without null character
                                   int z = 0;//index of reverse array
                                   int i = 0, j = length;//j backward jany ka ly
                                   while (ch[i] != ch[x])//jab tak last index of array nhi ajata
                                   {
                                   if (ch[j] == ' ' || ch[j] == ch[0])//agr j barabar space ka or ya j barabar hai first
                                   index ka
                                   {
                                   if (ch[j] != ch[0])//agr ch[j] first index ka barabr nhi hai
                                   {
                                   int k = j + 1;//new variable k takh space sa agy ka indexs ko revers array ma copy
                                   karwa saky ,+1 is ley takh space sa agy sa start ho
                                   while (ch[k] != ' ' && ch[k] != '\0')//ch[k] agr space nhi or ch[k] null akhri wala
                                   bhi nhi hai
                                   {
                                   //kia kary
                                   reverse[z] = ch[k];//reverse array ka first to onward indexes ma wo ch[k] ko copy
                                   karta jay
                                   k++;//k ko agy next index pa la jay
                                   z++;// reverse array ka index ko bhi next move kary
                                   if (ch[k] == ' ' || ch[k] == '\0')//ch[k] agr space hai or ch[k] null akhri wala bhi
                                   nhi hai to
                                   {
                                   reverse[z] = ' ';//reverse ka z index ko space assign kar de
                                   z++;//reverse array index ++ ho jay takh usma space na ay
                                   }
                                   }
                                   }
                                   if (ch[j] == ch[0])//agr ch[j] first index hai
                                   {
                                   int m=z;
                                   int l=0;
                                   while(ch[l]!=' '){
                                   reverse[z] = ch[l];//reverse z ko ch[0] kar de
                                   m++;
                                   z++;
                                   l++;
                                   }
                                   }
                                   }
                                   i++, j--;//ch indexes ko move kary sath hi j akhri index ko bacward bhi chalay
                                   }
                                   reverse[x] = '\0';//jasy hi loop ruky reverse ka x last index ko null kar de takh
                                   array stop ho jay
                                   cout << reverse; return 0; }
                        
                    

Whats make this website differents from others?

Amazing Feature That Increase your Productivity

If you don't find any problem,in this website and if you have a very difficult assignment question that is not present on internet ,then you dont bother yourself,we are here to solve every problem of your life you just click on the Problem asking button and write your problem we slove the code of your problem and sent you on your email addres that you put in the sin up form.