Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 12

Question-1: Insetion in a sorted Array.

Solution:
#include"bits/stdc++.h"
using namespace std;
int main()
{
int n,a,temp,swip;
cout<<"How many number you want to input this program\n";

cin>>n;

int Arr[n+2];

cout<<"So,now input the Array element in this program\n";


for(a=1;a<=n;a++)
{
cin>>Arr[a-1];
}

cout<<"Input a element in this Array .It will be sorted automatically \n";


cin>>temp;

Arr[n]=temp;

for(a=n;a>=1;a--)
{
if(temp<Arr[a-1])
{
Arr[a+1]=Arr[a];
}
else
{
Arr[a++]=temp;
break;
}
}

cout<<"Now,your result will be shown in this consol \n";


for(a=0;a<=n;a++)
{
cout<<Arr[a]<<endl;
}

cout<<"The program is finished \a"<<endl;

return 0;
}

Output:
Question: Delete one an array element .
Solved:
#include"bits/stdc++.h"
using namespace std;
int main()
{
int n,a,temp;
cout<<"How many number you want to input this program\n";
cin>>n;

int Arr[n];

cout<<"So,now input the Array element in this program\n";


for(a=1;a<=n;a++)
{
cin>>Arr[a-1];
}

cout<<"In this Array which element you want to Delete .Just input the
serial number\n";
cin>>temp;

for(a=temp-1;a<n;a++)
{
Arr[a]=Arr[a+1];
}

Arr[n-1];

cout<<"Now,your result will be shown in this consol \n";


for(a=0;a<n-1;a++)
{
cout<<Arr[a]<<endl;
}

cout<<"The program is finished \a"<<endl;


return 0;
}
Output:
Question: Sum of the boundary elements of a two dimensional Matrix.
Solved:
#include"bits/stdc++.h"
using namespace std;
int main()
{
int n,i,j,sum=0;
cout<<"This program will help you to find the sum of the boundary element
of a dimensional array.\n\
So , now input the dimension of the Matrix"<<endl;
cin>>n;

int Arr[n+1][n+1];
cout<<"So,now input the Matrix element in this program\n";
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
cout<<"["<<i<<"]["<<j<<"]=";
cin>>Arr[i][j];
if(i==1 || i==n)
sum+=Arr[i][j];

else if(j==1 || j==n)


sum+=Arr[i][j];
}

cout<<endl;
}

cout<<"Matrix:\n";
for(i=1;i<=n;i++)
{

for(j=1;j<=n;j++)
{
//cout<<"["<<i<<"]["<<j<<"]=";
cout<<Arr[i][j]<<" ";
}

cout<<endl;
}

cout<<"Now,the sum of Matrix of boundary element of two dimensional


="<<sum<<endl;

return 0;
}
Output:

Question:Sum of the diagonal element of a two dimensional Matrix.


Solved:
#include"bits/stdc++.h"
using namespace std;
int main()
{
int n,i,j,sum=0;
cout<<"This program will help you to find the sum of the diagonal element
of a two dimensional array.\n\
So , now input the dimension of the Matrix"<<endl;
cin>>n;

int Arr[n+1][n+1];

cout<<"So,now input the Matrix element in this program\n";


for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
cout<<"["<<i<<"]["<<j<<"]=";
cin>>Arr[i][j];
if(i==j)
sum+=Arr[i][j];
}

cout<<endl;
}

cout<<"Matrix:\n";
for(i=1;i<=n;i++)
{

for(j=1;j<=n;j++)
{
//cout<<"["<<i<<"]["<<j<<"]=";
cout<<Arr[i][j]<<" ";
}
cout<<endl;
}
cout<<"Now,the sum of Matrix of diagonal element of two dimensional
="<<sum<<endl;

return 0;
}
Output:

Question: Merge two sorted Array.


Solved:

#include"bits/stdc++.h"
using namespace std;
int main()
{
int n,i,j,tem;
cout<<"Input the 1st Array element number\n"<<endl;
cin>>n;
int Arr[n];

cout<<"So,now input the 1st Array element element in this program\n";

for(i=0;i<n;i++)
{

cin>>Arr[i];

cout<<"Input the second Array element number \n";


cin>>n;

int Brr[n];

Arr[i+n];

cout<<"So,now input the 2nd Array element element in this program\n";

for(j=0;j<n;j++)
{

cin>>Brr[j];
Arr[j+i]=Brr[j];
}

n=i+n;

for(j=0;j<n;j++)
{

for(i=j+1;i<n;i++)
{
if(Arr[j]<Arr[i])
{
tem=Arr[j];
Arr[j]=Arr[i];
Arr[i]=tem;
}
}

cout<<"Now,the two array merge in a sorted way\n Result:"<<endl;


for(i=0;i<n;i++)
{
cout<<Arr[i]<<endl;
}

return 0;
}

Output:

You might also like