Solution 12 to 25
Solution 14

Appending Two Arrays in C

This program demonstrates how to append the elements of one array to another in C. The user is prompted to enter the size and elements of two arrays. The program then combines the second array with the first array and displays the resulting array.

Code Breakdown

Algorithm

  1. Step Start
  2. Initialize Arrays:
    • Define arrays a and b to hold the elements of the first and second arrays respectively.
  3. Input First Array:
    • Prompt the user to enter the size of the first array (m).
    • Read m elements into array a.
  4. Input Second Array:
    • Prompt the user to enter the size of the second array (n).
    • Read n elements into array b.
  5. Append Second Array to First Array:
    • Loop through each element in array b and add it to the end of array a.
  6. Display Resulting Array:
    • Print the combined array a.
  7. Step End

Code Explanation

Example Flowchart


                                 Start
                                   |
                                   V
         Prompt user for size of first array `m` -----> Input `m`
                                   |
                                   V
             Prompt user for `m` elements of first array `a`
                                   |
                                   V
                    Input elements into array `a`
                                   |
                                   V
        Prompt user for size of second array `n` -----> Input `n`
                                   |
                                   V
            Prompt user for `n` elements of second array `b`
                                   |
                                   V
                     Input elements into array `b`
                                   |
                                   V
                For each element in `b`, append to `a`
                                   |
                                   V
                Display elements of combined array `a`
                                   |
                                   V
                                  End