Wednesday, April 22, 2020

Merge of array in C

  • Flowchat :

  • Program :

#include<stdio.h>
#include<coio.h>
void main()
{
  int aSize, bSize, mSize, i, j;
int a[10], b[10], Merged[20];
        clrscr();
        printf("\n----------------MERGE OF ARRAY----------------");
  printf("\n Please Enter the First Array Size  :  ");
  scanf("%d", &aSize);

  printf("\nPlease Enter the First Array Elements :  ");
  for(i = 0; i < aSize; i++)
  {
      scanf("%d", &a[i]);
  }
  printf("\n Please Enter the Second Array Size  :  ");
  scanf("%d", &bSize);
 
  printf("\nPlease Enter the Second Array Elements  :  ");
  for(i = 0; i < bSize; i++)
  {
      scanf("%d", &b[i]);
  }
 
  for(i = 0; i < aSize; i++)
  {
      Merged[i] = a[i];
  }
 
mSize = aSize + bSize;

  for(i = 0, j = aSize; j < mSize && i < bSize; i++, j++)
  {
  Merged[j] = b[i];
  }

  printf("\n a[%d] Array Elements After Merging \n", mSize);
  for(i = 0; i < mSize; i++)
  {
    printf(" %d \t ",Merged[i]);
  }

  getch();
}




  • Output :


No comments:

Post a Comment

Function Overloading in C++

https://monitechvenkat1620.blogspot.com Program : #include <iostream> using namespace std; int c(int x, int y) {   return...