C++ Programing (Combine two arrays into One Array)

Here you will find the solution of combining two arrays into one array:
for example: one array input first name :NOMAN and secondname KHAN, both combine into one array named FullName: NOMANKHAN.
Display will be NOMANKHAN without spaces.
________________________________________________________________________
#include <iostream.h>
#include <conio.h>

int main(void)
{
   char firstName[10];
   char lastName[10];
   char fullName[20];
   cout << "Enter Your first Name: ";
   cin >> firstName;

   cout << "Enter Your Last Name: ";
   cin >> lastName;

   int fSize = strlen(firstName);
   int lSize = strlen(lastName);

   //for full Name array
   int index = 0;

   //copy firstName array into fullName array
   for (int i = 0; i < fSize; i++)
   {
    fullName[index] = firstName[i];
      index++;    }

   //Now copy the lastName array into FullName but start from the index updated last time
   for (int j = 0; j < lSize; j++)
   {
    fullName[index] = lastName[j];
      index++;    }

   //display fullName
   for (int k = 0; k <= index; k++)
   {
    cout << fullName[k];     }

   getch();
   return 0;

}



Comments

Popular posts from this blog

Linear Search in C++

Advance Calculator in JavaScript