You are on page 1of 6

/*A program to delete all the instances of a given key in a vector (1 dimensional array).

Consider all the conditions.*/


#include<bits/stdc++.h>

using namespace std;

int main()

long n,key;

//input size of array

cout<<"Enter size of the array - ";

cin>>n;

//input key

cout<<"Enter key - ";

cin>>key;

//create array of size n

long array[n];

// input elements in the array

cout<<"Input elements of the array - "<<endl;

for(long i=0;i<n;i++) cin>>array[i];

//printing the input array

cout<<"\nThe Original Array is - "<<endl;

for(long i=0;i<n;i++) cout<<array[i]<<" ";

//count of number of elements equal to key

long count =0;cout<<endl;


//shifts every element back

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

array[i-count]=array[i];

if(array[i]==key)count++;

//size of the array after deleting

n=n-count;

//printing the new array

cout<<"The New Array is -"<<endl;

for(long i=0;i<n;i++)cout<<array[i]<<" ";

//case handling where all elements equal to key

if(n==0)cout<<"Array Empty"<<endl;

return 0;

}
/*A program to delete all the duplicate instances in a vector (1 dimensional array). */
#include<bits/stdc++.h>

using namespace std;

int main()

long n,key;

//input size of array

cout<<"Enter size of the array - ";

cin>>n;

//create array of size n

long array[n];

// input elements in the array

cout<<"Input elements of the array - "<<endl;

for(long i=0;i<n;i++)cin>>array[i];

cout<<endl<<endl;

//printing the input array

cout<<"The Original Array is - "<<endl;

for(long i=0;i<n;i++) cout<<array[i]<<" ";

cout<<endl;

for(long k=0;k<n;k++)

//stores the key

long key=array[k];

//count of number of elements equal to key


long count =0;

//shifts every element back

for(long i=k+1;i<n;i++)

array[i-count]=array[i];

if(array[i]==key)count++;

//size of the array after deleting keys

n=n-count;

//printing the new array

cout<<"The New Array is -"<<endl;

for(long i=0;i<n;i++) cout<<array[i]<<" ";

return 0;

}
/*A program to check whether a given square matrix is orthogonal. */

#include<bits/stdc++.h>

using namespace std;

int main()

long n;

cout<<"enter size of square matrix:";

cin>>n;

long array[n][n],ans[n][n];//array declaration

cout<<"enter array elements:\n";

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

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

cin>>array[i][j];// taking array elements

cout<<"array is:\n";

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

{ //printing original matrix

for(long j=0;j<n;j++) cout<<array[i][j]<<" ";

cout<<endl;

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

{ //finding A*A' matrix

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

ans[i][j]=0;

for(long k=0;k<n;k++)

ans[i][j]+=array[i][k]*array[j][k];

}
}

long check=1;

cout<<"\n\nA*A\':\n";

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

{//checking A*A' with Identity matrix

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

cout<<ans[i][j]<<" ";

if((i==j&&ans[i][j]!=1)||(i!=j&&ans[i][j]!=0))check=0;

cout<<endl;

if(check==0)cout<<"\nNOT Orthogonal";

else cout<<"\nOrthogonal";

return 0;

You might also like