Skip to content
This repository was archived by the owner on Oct 25, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 116 additions & 0 deletions Computer Science - BE/Sem 5/Sem 3/UCS301/Assignment_1/Q1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,x;
int a,b,c;
int pos;
int key;
int array[100];
int ch = 0;
int flag = 0;
int choice;
while(true)
{
cout<<"--MENU--"<<endl;
cout<<"1.CREATE"<<endl;
cout<<"2.DISPLAY"<<endl;
cout<<"3.INSERT"<<endl;
cout<<"4.DELETE"<<endl;
cout<<"5.SEARCH"<<endl;
cout<<"6.EXIT"<<endl;
cout<<"Enter Your choice "<<endl;
cin>>choice;
switch(choice)
{


case 1:
{
cout<<"Enter the size of an array "<<endl;
cin>>n;
cout<<"Enter the elements of the array "<<endl;
for(int i=0; i<n; i++)
{
cin>>array[i];
}
break;
}



case 2:
{
cout<<"The Elements of the array are "<<endl;
for(int i=0; i<n; i++)
{
cout<<array[i]<<" ";
}
cout<<endl;
break;
}



case 3:
{
cout<<"REnter the element to be inserted "<<endl;
cin>>a;
cout<<"Enter the position at which element to be inserted "<<endl;
cin>>b;
for(int i = n; i>=b; i--)
{
array[i+1] = array[i];
}
array[b] = a;
break;
}


case 4:
{
cout<<"Enter the position of the element to be deleted "<<endl;
cin>>pos;
while(pos-1<n)
{
array[pos-1] = array[pos];
pos++;
}
n--;
break;
}

case 5:
{
cout<<"Enter the element to be searched "<<endl;
cin>>key;
for(int i=0;i<n;i++)
{
if(array[i] == key)
{
flag = 1;
c = i;
break;
}
}
if(flag == 0)
cout<<"Element not found "<<endl;
else
{
cout<<"Element is found at index "<<c<<endl;
}
break;
}

case 6:
{
exit(0);
}

default:
cout<<"Invalid choice"<<endl;
}
}
return 0;
}

36 changes: 36 additions & 0 deletions Computer Science - BE/Sem 5/Sem 3/UCS301/Assignment_1/Q2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include<iostream>
using namespace std;
int main()
{
int n;
cout<<"Enter the size of the array "<<endl;
cin>>n;
int array[n];
cout<<"Enter the elements of the array "<<endl;
for(int i=0;i<n; i++)
{
cin>>array[i];
}
for(int i=0; i<n; i++)
{
int num = array[i];
for(int j=i+1; j<n; j++)
{
if(num == array[j])
{
while(j<n)
{
array[j-1] = array[j];
j++;
}
n--;
}
}
}
cout<<"Final Array: "<<endl;
for(int i=0; i<n; i++)
{
cout<<array[i]<<" ";
}
return 0;
}
26 changes: 26 additions & 0 deletions Computer Science - BE/Sem 5/Sem 3/UCS301/Assignment_1/Q4a.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cout<<"Enter the size of an array "<<endl;
cin>>n;
int array[n];
cout<<"Enter the elements of the array "<<endl;
for(int i=0;i<n;i++)
{
cin>>array[i];
}
cout<<"Array before reversing: "<<endl;
for(int i=0;i<n;i++)
{
cout<<array[i]<<" ";
}
cout<<endl;
cout<<"Array after reversing: "<<endl;
for(int i=n-1;i>=0; i--)
{
cout<<array[i]<<" ";
}
return 0;
}
55 changes: 55 additions & 0 deletions Computer Science - BE/Sem 5/Sem 3/UCS301/Assignment_1/Q4b.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#include <iostream>
using namespace std;
int main()
{
int n1, n2, n3;
cin>>n1>>n2>>n3;

int m1[n1][n2];
int m2[n2][n3];

for(int i=0;i<n1;i++)
{
for(int j=0;j<n2;j++)
{
cin>>m1[i][j];
}
}

for(int i=0;i<n2;i++)
{
for(int j=0;j<n3;j++)
{
cin>>m2[i][j];
}
}

int ans[n1][n3];
for(int i=0;i<n2;i++)
{
for(int j=0;j<n3;j++)
{
ans[i][j] = 0;
}
}

for(int i=0;i<n1;i++)
{
for(int j=0;j<n3;j++)
{
for(int k=0; k<n2;k++)
{
ans[i][j] += m1[i][k] * m2[k][j];
}
}
}
for(int i=0;i<n1; i++)
{
for(int j=0; j<n3; j++)
{
cout<<ans[i][j]<<" ";
}
cout<<endl;
}
return 0;
}
36 changes: 36 additions & 0 deletions Computer Science - BE/Sem 5/Sem 3/UCS301/Assignment_1/Q4c.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include<iostream>
using namespace std;
int main()
{
int i,j,m,n;
cout<<"Enter the number of rows "<<endl;
cin>>n;
cout<<"enter the number of columns "<<endl;
cin>>m;
int array[n][m];
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
cin>>array[i][j];
}
}
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
int temp = array[i][j];
array[i][j] = array[j][i];
array[j][i] = temp;
}
}
for(int i=0;i<n;i++)
{
for(int j=0; j<m;j++)
{
cout<<array[j][i]<<" ";
}
cout<<endl;
}
return 0;
}
43 changes: 43 additions & 0 deletions Computer Science - BE/Sem 5/Sem 3/UCS301/Assignment_1/Q5.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include<iostream>
using namespace std;
int binarysearch(int n, int array[], int key)
{
int s =0;
int e=n;
while(s<=e)
{
int mid = (s+e)/2;

if(array[mid] == key)
{
return mid;
}
else if(array[mid] > key)
{
e = mid - 1;
}
else
{
s = mid + 1;
}
}
return -1;
}
int main()
{
int n;
cout<<"Enter the size of an array "<<endl;
cin>>n;
int array[n];
cout<<"Enter the elements in an array "<<endl;
for(int i=0; i<n; i++)
{
cin>>array[i];
}
int key;
cout<<"Enter the key to be searched "<<endl;
cin>>key;
cout<<binarysearch(n, array, key)<<endl;
}


25 changes: 25 additions & 0 deletions Computer Science - BE/Sem 5/Sem 3/UCS301/Assignment_1/Q6.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <bits/stdc++.h>
using namespace std;
int main()
{
int array[7] = {64,34,25,12,22,11,90};
int counter = 1;
while(counter < 7)
{
for(int i=0;i<7-counter;i++)
{
if(array[i]>array[i+1])
{
int temp;
temp = array[i];
array[i] = array[i+1];
array[i+1] = temp;
}
}
counter++;
}
for(int i=0;i<7;i++)
{
cout<<array[i]<<" ";
}
}
37 changes: 37 additions & 0 deletions Computer Science - BE/Sem 5/Sem 3/UCS301/Assignment_1/Q7.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include <iostream>
using namespace std;
int main()
{
int n;
cout<<"Enter the size of an array "<<endl;
cin>>n;
int array[n];
cout<<"Enter the elements of the array "<<endl;
for(int i=0;i<n;i++)
{
cin>>array[i];
}
for(int i=0;i<n-1;i++)
{
for(int j=i+1;j<n;j++)
{
if(array[j] < array[i])
{
int temp;
temp = array[j];
array[j] = array[i];
array[i] = array[j];
}
}
}
for(int i=0; i<n; i++)
{
if(array[i+1] - array[i] == 2)
{
cout<<"The missing element of the sorted array is "<<array[i+1] - 1<<endl;
}
}
return 0;
}


Loading