Lab Task: 1: Insert Any Element in Array Code
Lab Task: 1: Insert Any Element in Array Code
Lab Task: 1: Insert Any Element in Array Code
Lab Task: 1
Insert any element in array
Code
#include<iostream>
#include<conio.h> using namespace std;
int main(){
int arr[50], size, in, i, p;
cout<<"Enter Array Size : ";
cin>>size;
cout<<"Enter array elements : ";
for(i=0; i<size; i++)
{
cin>>arr[i];}
cout<<"Enter element to be in : ";
cin>>in;
cout<<"At which position or enter index number) ? ";
cin>>p;
9/19/2019
1
Lab report 3
Lab Task: 2
Find smallest and largest number in array
Code
#include<iostream>
using namespace std;
int main ()
{
int arr[10], n, i, max, min;
cout << " size of the array : ";
cin >> n;
cout << "Enter the elements : ";
for (i = 0; i < n; i++)
cin >> arr[i];
max = arr[0];
for (i = 0; i < n; i++) {
if (max < arr[i])
max = arr[i];
}
min = arr[0];
for (i = 0; i < n; i++) {
if (min > arr[i])
min = arr[i]; }
cout << "Largest : " << max;
cout << "\nSmallest : " << min; }
Output
9/19/2019
2
Lab report 3
Lab Task: 3
Merge two arrays in such a way that resultant array will store in third array
Code
#include<iostream>
#include<conio.h>
9/19/2019
3
Lab report 3
Lab Task: 4 ,5
4- delete any element from array
Code
#include<iostream>
#include<process.h>
using namespace std;
int main({
int a[50],x,n,i,j,b[50];
cout<<"enter the size of array: ";
cin>>n;
cout<<"\nEnter elements of Array\n";
for(i=0;i<n;++i)
cin>>a[i];
cout<<"\nEnter element to delete:";
cin>>x;
for(i=0,j=0;i<n;++i){
if(a[i]!=x)
b[j++]=a[i];
}if(j==n){
cout<<"\nSoory!!!Element is not in the Array";
exit(0);
}else {
cout<<"\nNew Array is ";
for(i=0;i<j;i++)
cout<<b[i]<<" ";}
return 0; }
Output
9/19/2019