0% found this document useful (0 votes)
9 views

1-D Arrays: 1.//program To Input 2 Arrays and Merge Them Into One

The document contains two programs that work with 1-D arrays. The first program merges two integer arrays into a third array. It prompts the user to enter the sizes of the two arrays, reads their elements, and copies the elements of the first array followed by the second array into the merged array. The second program finds the largest and smallest elements in a 1-D integer array. It prompts the user for the array size, reads the elements, initializes the small and large variables, and loops through the array to update the small and large values.

Uploaded by

Vetty Vignesh
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

1-D Arrays: 1.//program To Input 2 Arrays and Merge Them Into One

The document contains two programs that work with 1-D arrays. The first program merges two integer arrays into a third array. It prompts the user to enter the sizes of the two arrays, reads their elements, and copies the elements of the first array followed by the second array into the merged array. The second program finds the largest and smallest elements in a 1-D integer array. It prompts the user for the array size, reads the elements, initializes the small and large variables, and loops through the array to update the small and large values.

Uploaded by

Vetty Vignesh
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

//1-D Arrays

1.//Program to input 2 arrays and merge them into one


#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a[10],b[10],c[20],m,n,i,j;
cout<<"Enter the size of first array";
cin>>m;
cout<<"\nEnter elements";
for(i=0;i<m;++i)
cin>>a[i];
cout<<"\nEnter the size of second array";
cin>>n;
cout<<"\nEnter elements";
for(j=0;j<n;++j)
cin>>b[j];
for(i=0;i<m;++i) //Copying a in c
c[i]=a[i];
for(j=0;j<n;++j)
c[i+j]=b[j]; //Copying b in c

cout<<"\nThe merged array is\n";
for(i=0;i<m+n;++i)
cout<<c[i]<<'\t';
getch();
}

2.//Program to display largest and smallest element in
1-d array
#include<iostream.h>
#include<conio.h>
void main()
{
int Arr[100],n,small,large;
cout<<"Enter number of elements you want to insert ";
cin>>n;
cout<<"\nEnter elements ";
for(i=0;i<n;++i)
{
cin>>Arr[i];
}

small=Arr[0];
large=Arr[0];

for(i=1;i<n;i++)
{
if(Arr[i]<small)
small=Arr[i];
if(Arr[i]>large)
large=Arr[i];
}

cout<<"\nLargest element is :"<<large;
cout<<"\nSmallest element is :"<<small;

getch();

}

You might also like