diff --git a/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/2DArrays/2dArraysDemo.cpp b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/2DArrays/2dArraysDemo.cpp new file mode 100644 index 00000000..1f65b88c --- /dev/null +++ b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/2DArrays/2dArraysDemo.cpp @@ -0,0 +1,20 @@ +#include<iostream> +using namespace std; + +int main() +{ + int n,m,i,j; + cin>>n>>m; + int arr[n][m]; + for(i=0;i<n;i++) + for(j=0;j<m;j++) + cin>>arr[i][j]; + for(i=0;i<n;i++) + { + for(j=0;j<m;j++) + { + cout<<arr[i][j]<<" ";\ + } + cout<<endl; + } +} \ No newline at end of file diff --git a/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/2DArrays/ExitPointOfAMatrix.cpp b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/2DArrays/ExitPointOfAMatrix.cpp new file mode 100644 index 00000000..498dd2af --- /dev/null +++ b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/2DArrays/ExitPointOfAMatrix.cpp @@ -0,0 +1,63 @@ +#include <iostream> +using namespace std; + + +const int mr = 100, mc = 100; + +int** input(int** mat, int n, int m) +{ + mat = new int* [n]; + for (int i = 0; i < n; i++) + { + int* arr = new int[m]; + for (int j = 0; j < m; j++) + { + cin >> arr[j]; + } + mat[i] = arr; + } + return mat; +} + + +int main(int argc, char** argv) +{ + int d=0,m,n; //0-e 1-s 2-w 3-n + cin >> n >> m; + int** mat = input(mat, n, m); + int i=0,j=0; + while(1) + { + d= (d+mat[i][j] )%4; + if(d==0) + j++; + else if(d==1) + i++; + else if(d==2) + j--; + else if(d==3) + i--; + if(i<0) + { + i++; + break; + } + else if(j<0) + { + j++; + break; + } + else if(i==n) + { + i--; + break; + } + else if(j==m) + { + j--; + break; + } + } + cout<<i<<endl<<j; + return 0; +} \ No newline at end of file diff --git a/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/2DArrays/ExitPointofMatrix.cpp b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/2DArrays/ExitPointofMatrix.cpp new file mode 100644 index 00000000..a8f6e5d9 --- /dev/null +++ b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/2DArrays/ExitPointofMatrix.cpp @@ -0,0 +1,46 @@ +#include <iostream> +using namespace std; + + +int main() +{ + int i=0,j=0,dir,row,curr,col; + cin>>row>>col; + int **arr = new int*[row]; + for(i=0;i<row;i++){ + arr[i]=new int[col]; + for(j=0;j<col;j++) + cin>>arr[i][j]; + } + dir = 0,i=0,j=0; + while(i<row && j<col){ + if(dir%4==0){ + if(j+1==col) + break; + dir += arr[i][++j]; + } + else if(dir%4==1){ + if(i+1==row) + break; + dir += arr[++i][j]; + } + else if(dir%4==2){ + if(j==0) + break; + dir += arr[i][--j]; + } + else if(dir%4==3){ + if(i==0) + break; + dir += arr[--i][j]; + } + } + cout<<i<<endl<<j; + /* + if(i==row) + cout<<i-1<<endl<<j; + else + cout<<i<<endl<<j-1; + */ + return 0; +} \ No newline at end of file diff --git a/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/2DArrays/MatrixMultiplication.cpp b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/2DArrays/MatrixMultiplication.cpp new file mode 100644 index 00000000..573ed3dd --- /dev/null +++ b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/2DArrays/MatrixMultiplication.cpp @@ -0,0 +1,46 @@ +#include<iostream> +using namespace std; + +int main() +{ + int n1,m1,n2,m2,i,j,k; + cin>>n1>>m1; + int a[n1][m1]; + for(i=0;i<n1;i++) + for(j=0;j<m1;j++) + cin>>a[i][j]; + + cin>>n2>>m2; + int b[n2][m2]; + for(i=0;i<n2;i++) + for(j=0;j<m2;j++) + cin>>b[i][j]; + + int c[n1][m2]; + if(m1 != n2) + cout<<"Invalid input"; + else + { + for(i=0;i<n1;i++) + { + for(j=0;j<m2;j++) + { + c[i][j]=0; + for(k=0;k<m1;k++){ + c[i][j] += a[i][k]*b[k][j]; + } + } + } + + for(i=0;i<n1;i++) + { + for(j=0;j<m2;j++) + { + cout<<c[i][j]<<" "; + } + cout<<endl; + } + } + + +} diff --git a/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/2DArrays/RingRotate.cpp b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/2DArrays/RingRotate.cpp new file mode 100644 index 00000000..28e29071 --- /dev/null +++ b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/2DArrays/RingRotate.cpp @@ -0,0 +1,68 @@ +#include<iostream> +using namespace std; + +void rotate(long int* arr2, int n,int k){ + int i,j=n; + long int *temp = new long int[n]; + if(k<0) + k+=n; + for(i=k-1;i>=0;i--) + temp[i] = arr2[--j]; + j=0; + for(i=k;i<n;i++) + temp[i]=arr2[j++]; + for(i=0;i<n;i++) + arr2[i] = temp[i]; + // write your code here + +} + +int main() +{ + int s,r,row,col,i,j; + cin>>row>>col; + long int **arr1 = new long int*[row]; + for(i=0;i<row;i++){ + arr1[i] = new long int[col]; + for(j=0;j<col;j++) + cin>>arr1[i][j]; + } + cin>>s; + cin>>r; + int nelements = 2*(row+col-2*(2*s-1)); + r = r%nelements; + long int*arr2 = new long int[nelements]; + int ind=0; + for(j=s-1;j<row-s;j++) + arr2[ind++] = arr1[j][s-1]; + for(j=s-1;j<col-s;j++) + arr2[ind++] = arr1[row-s][j]; + for(j=row-s;j>s-1;j--) + arr2[ind++] = arr1[j][col-s]; + for(j=col-s;j>s-1;j--) + arr2[ind++] = arr1[s-1][j]; + + /* + for(i=0;i<nelements;i++) + cout<<arr2[i]<<" "; + */ + + rotate(arr2,nelements,r); + ind = 0; + + for(j=s-1;j<row-s;j++) + arr1[j][s-1] = arr2[ind++]; + for(j=s-1;j<col-s;j++) + arr1[row-s][j] = arr2[ind++]; + for(j=row-s;j>s-1;j--) + arr1[j][col-s] = arr2[ind++]; + for(j=col-s;j>s-1;j--) + arr1[s-1][j] = arr2[ind++]; + + for(i=0;i<row;i++){ + for(j=0;j<col;j++) + cout<<arr1[i][j]<<" "; + cout<<endl; + } + +} \ No newline at end of file diff --git a/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/2DArrays/RotateBy90Degree.cpp b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/2DArrays/RotateBy90Degree.cpp new file mode 100644 index 00000000..c6933774 --- /dev/null +++ b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/2DArrays/RotateBy90Degree.cpp @@ -0,0 +1,29 @@ +#include <iostream> +#include <vector> +#include <algorithm> +using namespace std; + +void rotate(int n, vector<vector<int>> &arr) +{ + int i,j; + for(i=0;i<n;i++) + { + for(j=n-1; j>=0;j--) + { + cout<<arr[j][i]<<" "; + } + cout<<endl; + } + +} + +int main() +{ + int n; + cin >> n; + vector<vector<int>> arr(n, vector<int>(n)); + for (int i = 0; i < n; i++) + for (int j = 0; j < n; j++) + cin >> arr[i][j]; + rotate(n, arr); +} \ No newline at end of file diff --git a/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/2DArrays/Rotateby90.cpp b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/2DArrays/Rotateby90.cpp new file mode 100644 index 00000000..98888963 --- /dev/null +++ b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/2DArrays/Rotateby90.cpp @@ -0,0 +1,30 @@ +#include <iostream> +using namespace std; + + +int main() +{ + int n,i,i2,j; + cin>>n; + int **arr = new int*[n]; + for(i=0;i<n;i++){ + arr[i] = new int[n]; + for(j=0;j<n;j++) + cin>>arr[i][j]; + } + int **arr2 = new int*[n]; + for(i=0;i<n;i++) + arr2[i] = new int[n]; + i2 = -1; + for(i=n-1;i>=0;i--){ + i2++; + for(j=0;j<n;j++) + arr2[j][i2] = arr[i][j]; + } + for(i=0;i<n;i++){ + for(j=0;j<n;j++){ + cout<<arr2[i][j]<<" "; + } + cout<<endl; + } +} \ No newline at end of file diff --git a/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/2DArrays/Sadle.cpp b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/2DArrays/Sadle.cpp new file mode 100644 index 00000000..ddf22cdf --- /dev/null +++ b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/2DArrays/Sadle.cpp @@ -0,0 +1,42 @@ +#include <iostream> +using namespace std; + +bool constraint(long int i){ + if(i> -1000000000 && i< 1000000000) + return true; + return false; +} + +int main() +{ + int n,i,j; + cin >> n; + long int** arr = new long int*[n]; + int* min = new int[n]; + for(i = 0; i < n; i++) { + arr[i] = new long int[n]; + for (j = 0; j < n; j++) { + cin >> arr[i][j]; + if(constraint(arr[i][j])){ + if (j == 0) + min[i] = arr[i][j]; + else if (arr[i][j] < min[i]) + min[i] = arr[i][j]; + } + else{ + cout<<"Invalid input"; + return 0; + } + } + } + for(i=0;i<n;i++){ + for(j=0;j<n;j++){ + if(arr[j][i]>min[i]) + break; + } + //cout<<j<<" "<<min[i]<<endl; + if(j==n-1) + cout<<min[i]; + } + return 0; +} \ No newline at end of file diff --git a/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/2DArrays/SearchElement.cpp b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/2DArrays/SearchElement.cpp new file mode 100644 index 00000000..d7c7650e --- /dev/null +++ b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/2DArrays/SearchElement.cpp @@ -0,0 +1,36 @@ +#include <iostream> +using namespace std; + +void search(int **arr,int n, int row,int key){ + int i; + for(i=0;i<n;i++){ + if(arr[row][i]==key){ + cout<<row<<endl<<i; + break; + } + } + if(i==n) + cout<<"Not Found"; +} + +int main() +{ + int n, key,i,j; + cin >> n; + int **arr = new int*[n]; + for(i=0;i<n;i++){ + arr[i] = new int[n]; + for(j=0;j<n;j++) + cin>>arr[i][j]; + } + cin>>key; + i=0; + for(i=0;i<n;i++){ + if(key>= arr[i][0] && key<=arr[i][n-1]){ + search(arr,n,i,key); + break; + } + } + if(i==n) + cout<<"Not Found"; +} \ No newline at end of file diff --git a/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/2DArrays/SearchInASorted2dArray.cpp b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/2DArrays/SearchInASorted2dArray.cpp new file mode 100644 index 00000000..73eda870 --- /dev/null +++ b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/2DArrays/SearchInASorted2dArray.cpp @@ -0,0 +1,41 @@ +#include <iostream> +#include <vector> +using namespace std; + +bool searchMatrix(vector<vector<int>>& matrix, int target) +{ + int n= matrix.size(),r=-1,c=-1,i; + for(i=0;i<n;i++) + { + if(matrix[i][0] <= target && matrix[i][n-1] >= target) + { + r=i; + break; + } + } + if(r==-1) + return 0; + for(i=0;i<n;i++) + { + if(matrix[r][i]==target) + c=i; + } + + if(c==-1) + return 0; + cout<<r<<endl<<c; + return 1; +} + +int main() +{ + int n, target; + cin>>n; + vector<vector<int>> mat(n, vector<int> (n)); + for(int i = 0; i < n; i++) + for(int j = 0; j < n; j++) + cin>>mat[i][j]; + cin>>target; + + if(!searchMatrix(mat, target)) cout<<"Not Found\n"; +} \ No newline at end of file diff --git a/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/2DArrays/SpiralDisplay.cpp b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/2DArrays/SpiralDisplay.cpp new file mode 100644 index 00000000..ba08dfc5 --- /dev/null +++ b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/2DArrays/SpiralDisplay.cpp @@ -0,0 +1,47 @@ +#include <iostream> +using namespace std; + + +int main() +{ + int row,col,i,j,count=0; + cin>>row>>col; + int **arr = new int*[row]; + int minrow = 0, mincol = 0, maxrow = row-1, maxcol = col-1; + for(i=0;i<row;i + ++){ + arr[i] = new int[col]; + for(j=0;j<col;j++){ + cin>>arr[i][j]; + } + } + + while(count < row*col){ + + for(i=minrow; i<=maxrow && count< row*col; i++){ + cout<<arr[i][mincol]<<endl; + count++; + } + mincol++; + for(i=mincol; i<=maxcol && count < row*col; i++){ + cout<<arr[maxrow][i]<<endl; + count++; + } + maxrow--; + for(i=maxrow; i>=minrow && count< row*col; i--){ + cout<<arr[i][maxcol]<<endl; + count++; + } + maxcol--; + for(i=maxcol; i>=mincol && count< row*col; i--){ + cout<<arr[minrow][i]<<endl; + count++; + } + minrow++; + + } + + // write your code here + + return 0; +} \ No newline at end of file diff --git a/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/2DArrays/TheStateOfWakanda-1.cpp b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/2DArrays/TheStateOfWakanda-1.cpp new file mode 100644 index 00000000..6d9b23e8 --- /dev/null +++ b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/2DArrays/TheStateOfWakanda-1.cpp @@ -0,0 +1,41 @@ +#include<iostream> +#include<vector> + +using namespace std; + +void columnTraversal(vector<vector<int>> mat){ + int r=mat.size(); + int c=mat[0].size(); + int i,j=0; + while(j<c) + { + for(i=0;i<r;i++) + cout<<mat[i][j]<<endl; + j++; + if(j<c) + { for(i=r-1;i>=0;i--) + cout<<mat[i][j]<<endl; + j++; + } + } +} + +int main(){ + int n; + int m; + cin>> n; + cin>> m; + + vector<vector<int>> mat; + for(int i= 0; i< n; i++){ + vector<int> arr; + for(int j= 0; j< m; j++){ + int ele; + cin>> ele; + arr.push_back(ele); + } + mat.push_back(arr); + } + + columnTraversal(mat); +} \ No newline at end of file diff --git a/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/2DArrays/TheStateOfWakanda-2.cpp b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/2DArrays/TheStateOfWakanda-2.cpp new file mode 100644 index 00000000..dafd12fb --- /dev/null +++ b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/2DArrays/TheStateOfWakanda-2.cpp @@ -0,0 +1,28 @@ +#include <iostream> +#include <vector> +using namespace std; + +void upperDiagonal_traverse(int n, vector<vector<int>> &arr) +{ + int t=0,i,k; + for(k= n-1 ; k>=0; k--) + { + for(i=0;i<=k;i++) + { + cout<<arr[i][i+t]<<endl; + } + t++; + } +} + +int main() +{ + int n; + cin >> n; + vector<vector<int>> arr(n, vector<int>(n)); + for (int i = 0; i < n; i++) + for (int j = 0; j < n; j++) + cin >> arr[i][j]; + + upperDiagonal_traverse(n, arr); +} \ No newline at end of file diff --git a/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/2DArrays/Wakanda2.cpp b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/2DArrays/Wakanda2.cpp new file mode 100644 index 00000000..bb2007c4 --- /dev/null +++ b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/2DArrays/Wakanda2.cpp @@ -0,0 +1,26 @@ +#include <iostream> +using namespace std; + + +int main() +{ + int n; + cin >> n; + int arr[n][n]; + for (int i = 0; i < n; i++){ + for (int j = 0; j < n; j++) + cin >> arr[i][j]; + } + int head=0; + int i=0; + int j=0; + while(head<n){ + while(i<n && j<n){ + cout<<arr[i++][j++]<<endl; + } + head++; + i = 0; + j = head; + } + +} \ No newline at end of file diff --git a/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/2DArrays/demo.cpp b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/2DArrays/demo.cpp new file mode 100644 index 00000000..2ab4deca --- /dev/null +++ b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/2DArrays/demo.cpp @@ -0,0 +1,18 @@ +#include<iostream> +using namespace std; +int main() { + int i,j,row,col; + cin>>row>>col; + int arr[row][col]; + for(i=0;i<row;i++){ + for(j=0;j<col;j++) + cin>>arr[i][j]; + } + for(i=0;i<row;i++){ + for(j=0;j<col;j++) + cout<<arr[i][j]<<" "; + cout<<endl; + } +// Write your code here. + +} \ No newline at end of file diff --git a/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/2DArrays/matrixmult.cpp b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/2DArrays/matrixmult.cpp new file mode 100644 index 00000000..905aefd7 --- /dev/null +++ b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/2DArrays/matrixmult.cpp @@ -0,0 +1,41 @@ +#include<iostream> +using namespace std; + +int main(){ + int i,j,n1,m1,n2,m2,k=0; + cin>>n1>>m1; + int arr1[n1][m1]; + for(i=0;i<n1;i++){ + for(j=0;j<m1;j++) + cin>>arr1[i][j]; + } + cin>>n2>>m2; + int arr2[n2][m2]; + for(i=0;i<n2;i++){ + for(j=0;j<m2;j++) + cin>>arr2[i][j]; + } + if(m1!=n2){ + cout<<"Invalid input"; + return 0; + } + int arr3[n1][m2]; + for(i=0;i<n1;i++){ + for(j=0;j<m2;j++) + arr3[i][j]=0; + } + for(i=0;i<n1;i++){ + k=0; + while(k<m2){ + for(j=0;j<m1;j++) + arr3[i][k] += arr1[i][j]*arr2[j][k]; + k++; + } + } + for(i=0;i<n1;i++){ + for(j=0;j<m2;j++) + cout<<arr3[i][j]<<" "; + cout<<endl; + } + return 0; +} \ No newline at end of file diff --git a/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/2DArrays/wakanda1.cpp b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/2DArrays/wakanda1.cpp new file mode 100644 index 00000000..b0412830 --- /dev/null +++ b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/2DArrays/wakanda1.cpp @@ -0,0 +1,34 @@ +#include<iostream> + + +using namespace std; + + +int main() { + int i,j,start,end,row,col; + cin>>row>>col; + int arr[row][col]; + for(i=0;i<row;i++){ + for(j=0;j<col;j++) + cin>>arr[i][j]; + } + for(i=0;i<col;i++){ + if(i%2==0){ + start=0; + end=row; + } + else{ + start=row-1; + end=-1; + } + j=start; + while(j!=end){ + cout<<arr[j][i]<<endl; + if(start>end) + j--; + else + j++; + } + } + return 0; +} \ No newline at end of file diff --git a/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/AnyBaseAdd.cpp b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/AnyBaseAdd.cpp new file mode 100644 index 00000000..14ee522c --- /dev/null +++ b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/AnyBaseAdd.cpp @@ -0,0 +1,40 @@ +#include<iostream> +#include<cmath> + +using namespace std; + +int AnyToDec(int n, int b) { + int rem,num=0,i=0; + while(n>0){ + rem = n%10; + n=n/10; + num = num + rem*pow(b,i++); + } + return num; +//write your code here. +} + +void DecToAny(int n, int b) { + int binary[9],i=0; + for(i=0;i<9;i++) + binary[i]=-1; + i=0; + while(n>0){ + binary[i++]=n%b; + n = n/b; + } + for(i=8;i>=0;i--){ + if(binary[i] != -1) + cout<<binary[i]; + } +//write your code here +} + +int main() { + int b, n1, n2; + cin >> b >> n1 >> n2; + int nn1 = AnyToDec(n1,b); + int nn2 = AnyToDec(n2,b); + int sum = nn1 + nn2; + DecToAny(sum,b); +} \ No newline at end of file diff --git a/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/AnyBaseAddition.cpp b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/AnyBaseAddition.cpp new file mode 100644 index 00000000..60cdd6a7 --- /dev/null +++ b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/AnyBaseAddition.cpp @@ -0,0 +1,40 @@ +#include<iostream> + +using namespace std; + +int getSum(int b, int n1, int n2) { + int carry=0,i=0,j=0,k; + int d1[5]={},d2[5]={},sum[5],SUM=0; + while(n1) + { + d1[i++]=n1%10; + n1/=10; + } + while(n2) + { + d2[j++]=n2%10; + n2/=10; + } + for(k=0; k<i || k<j; k++) + { + sum[k]=(d1[k]+d2[k]+carry)%b ; + // cout<<d1[k]<<" "<<d2[k]<<" "<<carry<<" "<<sum[k]<<endl; + carry= (d1[k]+d2[k]+carry)/b; + } + if(carry) + sum[k++]=carry; + + for(i=k-1;i>=0;i--) + { + SUM=SUM*10+ sum[i]; + } + return SUM; + +} + + +int main() { + int b, n1, n2; + cin >> b >> n1 >> n2; + cout << getSum(b, n1, n2) << endl; +} \ No newline at end of file diff --git a/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/AnyBaseMult.cpp b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/AnyBaseMult.cpp new file mode 100644 index 00000000..a34e2eb4 --- /dev/null +++ b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/AnyBaseMult.cpp @@ -0,0 +1,40 @@ +#include<iostream> +#include<cmath> + +using namespace std; + +int AnyToDec(int n, int b) { + int rem,num=0,i=0; + while(n>0){ + rem = n%10; + n=n/10; + num = num + rem*pow(b,i++); + } + return num; +//write your code here. +} + +void DecToAny(int n, int b) { + int binary[9],i=0; + for(i=0;i<9;i++) + binary[i]=-1; + i=0; + while(n>0){ + binary[i++]=n%b; + n = n/b; + } + for(i=8;i>=0;i--){ + if(binary[i] != -1) + cout<<binary[i]; + } +//write your code here +} + +int main() { + int b, n1, n2; + cin >> b >> n1 >> n2; + int nn1 = AnyToDec(n1,b); + int nn2 = AnyToDec(n2,b); + int sum = nn1 * nn2; + DecToAny(sum,b); +} \ No newline at end of file diff --git a/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/AnyBaseSubs.cpp b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/AnyBaseSubs.cpp new file mode 100644 index 00000000..fc8a9ef5 --- /dev/null +++ b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/AnyBaseSubs.cpp @@ -0,0 +1,40 @@ +#include<iostream> +#include<cmath> + +using namespace std; + +int AnyToDec(int n, int b) { + int rem,num=0,i=0; + while(n>0){ + rem = n%10; + n=n/10; + num = num + rem*pow(b,i++); + } + return num; +//write your code here. +} + +void DecToAny(int n, int b) { + int binary[9],i=0; + for(i=0;i<9;i++) + binary[i]=-1; + i=0; + while(n>0){ + binary[i++]=n%b; + n = n/b; + } + for(i=8;i>=0;i--){ + if(binary[i] != -1) + cout<<binary[i]; + } +//write your code here +} + +int main() { + int b, n1, n2; + cin >> b >> n1 >> n2; + int nn1 = AnyToDec(n1,b); + int nn2 = AnyToDec(n2,b); + int sum = nn2 - nn1; + DecToAny(sum,b); +} \ No newline at end of file diff --git a/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/AnyBaseSubtraction.cpp b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/AnyBaseSubtraction.cpp new file mode 100644 index 00000000..1faa2bb3 --- /dev/null +++ b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/AnyBaseSubtraction.cpp @@ -0,0 +1,39 @@ +#include<iostream> +using namespace std; + +int getDifference(int b, int n1, int n2){ + int borrow=0,diff=0,d1[3]={},d2[3]={},i=0,j=0,l=0,d[3],k; + while(n2) + { + d2[i++]=n2%10; + n2/=10; + } + while(n1) + { + d1[j++]= n1%10; + n1/=10; + } + + for(k=0 ; k<3 ;k++) + { + if(d2[k]<d1[k]) + { + d2[k]+=b; + d2[k+1]-=1; + } + d[l++]=d2[k]-d1[k]; + } + for(i=2;i>=0;i--) + { + diff= diff*10 + d[i]; + } + cout<<diff; + return 0; +} + + +int main(){ + int b, n1, n2; + cin>>b>>n1>>n2; + getDifference(b,n1,n2); +} \ No newline at end of file diff --git a/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/AnyBaseToAnyBase.cpp b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/AnyBaseToAnyBase.cpp new file mode 100644 index 00000000..c4888670 --- /dev/null +++ b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/AnyBaseToAnyBase.cpp @@ -0,0 +1,41 @@ +#include <iostream> +#include <math.h> +using namespace std; +int anyBaseToDecimal(int n,int base) +{ + int i=0,num=0,arr[15]; + while(n) + { + arr[i++]=n%10; + n/=10; + } + for(int j=0;j<i;j++) + { + num += arr[j]*pow(base,j); + } + // cout<<num<<endl; + return num; + +} + +int decimalToAnyBase(int n,int base) +{ + int i=0,num=0,arr[15]; + while(n) + { + arr[i++]= n%base ; + n/=base; + } + for(int j=i-1;j>=0;j--) + num=num*10 + arr[j]; + return num; +} +int main() +{ + int n,b1,b2,dec,num; + cin>>n>>b1>>b2; + dec= anyBaseToDecimal(n,b1); + num= decimalToAnyBase(dec,b2); + cout<<num; + return 0; +} \ No newline at end of file diff --git a/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/AnyBaseToDecimal.cpp b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/AnyBaseToDecimal.cpp new file mode 100644 index 00000000..a43eef3c --- /dev/null +++ b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/AnyBaseToDecimal.cpp @@ -0,0 +1,21 @@ +#include<iostream> +#include <math.h> +using namespace std; + +int main() +{ + long long n; + int base,arr[15],i=0,num=0; + cin>>n>>base; + while(n) + { + arr[i++]=n%10; + n/=10; + } + for(int j=0;j<i;j++) + { + num += arr[j]*pow(base,j); + } + cout<<num; + return 0; +} \ No newline at end of file diff --git a/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/AnyToAny.cpp b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/AnyToAny.cpp new file mode 100644 index 00000000..c43b4368 --- /dev/null +++ b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/AnyToAny.cpp @@ -0,0 +1,42 @@ +#include<iostream> +#include<cmath> +using namespace std; + +int AnyToDec(int n, int b) { + int rem,num=0,i=0; + while(n>0){ + rem = n%10; + n=n/10; + num = num + rem*pow(b,i++); + } + return num; +//write your code here. +} + +void DecToAny(int n, int b) { + int binary[9],i=0; + for(i=0;i<9;i++) + binary[i]=-1; + i=0; + while(n>0){ + binary[i++]=n%b; + n = n/b; + } + for(i=8;i>=0;i--){ + if(binary[i] != -1) + cout<<binary[i]; + } +//write your code here +} + + +int main() { + int n; + int b1,b2; + cin >> n; + cin >> b1; + cin >> b2; + int res = AnyToDec(n, b1); + DecToAny(res,b2); + +} \ No newline at end of file diff --git a/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/AnyToDec.cpp b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/AnyToDec.cpp new file mode 100644 index 00000000..3de54b61 --- /dev/null +++ b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/AnyToDec.cpp @@ -0,0 +1,23 @@ +#include<iostream> +#include<cmath> +using namespace std; + +int AnyToDec(int n, int b) { + int rem,num=0,i=0; + while(n>0){ + rem = n%10; + n=n/10; + num = num + rem*pow(b,i++); + } + return num; +//write your code here. +} + +int main() { + int n; + int b; + cin >> n; + cin >> b; + int res = AnyToDec(n, b); + cout << res << endl; +} \ No newline at end of file diff --git a/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/BarChart.cpp b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/BarChart.cpp new file mode 100644 index 00000000..a81259eb --- /dev/null +++ b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/BarChart.cpp @@ -0,0 +1,40 @@ +#include<iostream> +using namespace std; + + +int main(){ + int n,i,j; + cin>>n; + int bar[n],max=0; + + for(i=0;i<n;i++){ + cin>>bar[i]; + if(bar[i]>max) + max=bar[i]; + } + + int graph[n][max]; + + for(i=0;i<n;i++){ + for(j=0;j<max;j++) + graph[i][j]=-1; + } + + for(i=0;i<n;i++){ + for(j=0;j<bar[i];j++) + graph[i][j]=0; + } + + for(i=max-1;i>=0;i--){ + for(j=0;j<n;j++){ + if(graph[j][i]==0) + cout<<"* "; + else + cout<<" "; + } + cout<<endl; + } + //write your code here + + +} \ No newline at end of file diff --git a/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/BrokenEconomy.cpp b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/BrokenEconomy.cpp new file mode 100644 index 00000000..56208919 --- /dev/null +++ b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/BrokenEconomy.cpp @@ -0,0 +1,31 @@ +#include<iostream> +using namespace std; + +int main(){ + int n,i; + cin>>n; + int* arr = new int[n]; + for(int i = 0 ; i < n; i++){ + cin>>arr[i]; + } + int data; + cin>>data; + for(i=0;i<n;i++){ + if(data==arr[i]){ + cout<<arr[i]; + return 0; + } + } + i=0; + while(data>arr[i]){ + i++; + } + if(i==n || i==0) + cout<<arr[i]; + else + cout<<arr[i]<<endl<<arr[i-1]<<endl; + + return 0; + // write your code here + +} \ No newline at end of file diff --git a/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/DecToAny.cpp b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/DecToAny.cpp new file mode 100644 index 00000000..7c012e58 --- /dev/null +++ b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/DecToAny.cpp @@ -0,0 +1,26 @@ +#include<iostream> +using namespace std; + +void DecToAny(int n, int b) { + int binary[9],i=0; + for(i=0;i<9;i++) + binary[i]=-1; + i=0; + while(n>0){ + binary[i++]=n%b; + n = n/b; + } + for(i=8;i>=0;i--){ + if(binary[i] != -1) + cout<<binary[i]; + } +//write your code here +} + +int main() { + int n; + int b; + cin >> n; + cin >> b; + DecToAny(n, b); +} \ No newline at end of file diff --git a/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/DecimalToAnyBase.cpp b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/DecimalToAnyBase.cpp new file mode 100644 index 00000000..e572b006 --- /dev/null +++ b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/DecimalToAnyBase.cpp @@ -0,0 +1,17 @@ +#include <iostream> +using namespace std; + +int main() +{ + long num=0,num2=0; + int n,base,arr[20],i=0; + cin>>n>>base; + while(n) + { + arr[i++]= n%base ; + n=n/base; + } + for(int j=i-1;j>=0;j--) + cout<<arr[j]; + return 0; +} \ No newline at end of file diff --git a/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/DigitFrequency.cpp b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/DigitFrequency.cpp new file mode 100644 index 00000000..49010053 --- /dev/null +++ b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/DigitFrequency.cpp @@ -0,0 +1,20 @@ +#include<iostream> +using namespace std; +int digFreq(int n, int d) { + int rem; + int count=0; + while(n>0){ + rem = n%10; + if(rem == d) + count++; + n = n/10; + } + return count; + //write your code here +} +int main() { + int n, d; + cin >> n >> d; + int res = digFreq(n, d); + cout << res << endl; +} \ No newline at end of file diff --git a/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/FindElement.cpp b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/FindElement.cpp new file mode 100644 index 00000000..cf5ab4ab --- /dev/null +++ b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/FindElement.cpp @@ -0,0 +1,21 @@ +#include<iostream> +using namespace std; + + +int main(){ + int n,i,num,d; + cin>>n; + int arr[n]; + for(i=0;i<n;i++) + cin>>arr[i]; + cin>>d; + for(i=0;i<n;i++){ + if(d==arr[i]){ + cout<<i<<endl; + break; + } + } + if(i==n) + cout<<"-1"<<endl; + //write your code here +} \ No newline at end of file diff --git a/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/FindElementInAnArray.cpp b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/FindElementInAnArray.cpp new file mode 100644 index 00000000..0b0b0a64 --- /dev/null +++ b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/FindElementInAnArray.cpp @@ -0,0 +1,23 @@ +#include<iostream> +using namespace std; + + +int main(){ + int n; + cin>>n; + int a[n],i,d,found=0; + for(i=0;i<n;i++) + cin>>a[i]; + cin>>d; + for(i=0;i<n;i++) + { + if(d==a[i]) + { + cout<<i; + found=1; + } + } + if(!found) + cout<<-1; + +} \ No newline at end of file diff --git a/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/FirstIndexAndLastIndex.cpp b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/FirstIndexAndLastIndex.cpp new file mode 100644 index 00000000..92a66d3e --- /dev/null +++ b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/FirstIndexAndLastIndex.cpp @@ -0,0 +1,43 @@ +#include<iostream> +using namespace std; + +int main(){ + int n; + cin>>n; + int* arr = new int[n]; + for(int i = 0 ; i < n; i++){ + cin>>arr[i]; + } + int data,high,low,mid,hi=-1,li=-1; + cin>>data; + + low=0; high=n-1; + while(low<=high) + { + mid=(high+low)/2; + if(arr[mid]>data) + high=mid-1; + else if(arr[mid]<data) + low=mid+1; + else + { + hi=mid; + low=mid+1; + } + } + low=0; high=n-1; + while(low<=high) + { + mid=(high+low)/2; + if(arr[mid]>data) + high=mid-1; + else if(arr[mid]<data) + low=mid+1; + else + { + li=mid; + high=mid-1; + } + } + cout<<li<<endl<<hi; +} \ No newline at end of file diff --git a/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/FirstIndexLastIndex.cpp b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/FirstIndexLastIndex.cpp new file mode 100644 index 00000000..c0f5ecf9 --- /dev/null +++ b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/FirstIndexLastIndex.cpp @@ -0,0 +1,28 @@ +#include<iostream> +using namespace std; + +int main(){ + int n,ans=-1,i; + cin>>n; + bool flag=true; + int* arr = new int[n]; + for(int i = 0 ; i < n; i++){ + cin>>arr[i]; + } + int data; + cin>>data; + for(i=0;i<n;i++){ + if(data==arr[i] && flag==true){ + cout<<i<<endl; + flag=false; + } + if(data==arr[i]) + ans = i; + } + if(flag==true) + cout<<-1<<endl; + cout<<ans<<endl; + // write your code here + + +} \ No newline at end of file diff --git a/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/InverseArray.cpp b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/InverseArray.cpp new file mode 100644 index 00000000..ffe58f4c --- /dev/null +++ b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/InverseArray.cpp @@ -0,0 +1,31 @@ +#include<iostream> +using namespace std; + +int* inverse(int* arr, int n){ + int* inv = new int[n]; + //int inv[n]; + for(int i = 0; i<n ; i++){ + inv[arr[i]] = i; + } + return inv; +} + +void display(int* arr, int n){ + for(int i = 0 ; i < n; i++){ + cout<<arr[i]<<endl; + } + cout<<endl; +} + +int main(){ + int n; + cin>>n; + int arr[n]; + for(int i = 0 ; i < n; i++){ + cin>>arr[i]; + } + + int* inv = inverse(arr,n); + display(inv,n); + +} \ No newline at end of file diff --git a/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/InverseOfAnArray.cpp b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/InverseOfAnArray.cpp new file mode 100644 index 00000000..e22dc5a7 --- /dev/null +++ b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/InverseOfAnArray.cpp @@ -0,0 +1,32 @@ +#include<iostream> +using namespace std; + +int* inverse(int* arr, int n){ + int a2[n],i; + for(i=0;i<n;i++) + a2[arr[i]]=i; + for(i=0;i<n;i++) + arr[i]=a2[i]; + return arr; + +} + +void display(int* arr, int n){ + for(int i = 0 ; i < n; i++){ + cout<<arr[i]<<endl; + } + cout<<endl; +} + +int main(){ + int n; + cin>>n; + int* arr = new int[n]; + for(int i = 0 ; i < n; i++){ + cin>>arr[i]; + } + + int* inv = inverse(arr,n); + display(inv,n); + +} \ No newline at end of file diff --git a/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/InvertedBarChart.cpp b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/InvertedBarChart.cpp new file mode 100644 index 00000000..1266f1b2 --- /dev/null +++ b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/InvertedBarChart.cpp @@ -0,0 +1,32 @@ +#include<iostream> +using namespace std; + + +int main() { + int i,n,t,j,max=0; + cin>>n; + char arr[n][10]; + for(i=0;i<n;i++){ + for(j=0;j<10;j++) + arr[i][j]=' '; + } + for(i=0;i<n;i++){ + cin>>t; + if(t>max) + max=t; + for(j=0;j<t;j++) + arr[i][j]='*'; + } + for(i=0;i<max;i++){ + for(j=0;j<n;j++){ + if(arr[j][i]=='*') + cout<<arr[j][i]<<" "; + else + cout<<arr[j][i]; + } + cout<<endl; + } + //write your code here + + +} \ No newline at end of file diff --git a/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/ReverseAnArray.cpp b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/ReverseAnArray.cpp new file mode 100644 index 00000000..bb95438c --- /dev/null +++ b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/ReverseAnArray.cpp @@ -0,0 +1,32 @@ +#include<iostream> +using namespace std; + +void reverse(int* arr, int n){ + int i,t; + for(i=0;i<n/2;i++) + { + t=arr[i]; + arr[i]=arr[n-i-1]; + arr[n-i-1]=t; + } + +} + +void display(int* arr, int n){ + for(int i = 0 ; i < n; i++){ + cout<<arr[i]<<" "; + } + cout<<endl; +} + +int main(){ + int n; + cin>>n; + + int* arr = new int[n]; + for(int i = 0 ; i < n; i++){ + cin>>arr[i]; + } + reverse(arr,n); + display(arr,n); +} \ No newline at end of file diff --git a/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/ReverseArray.cpp b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/ReverseArray.cpp new file mode 100644 index 00000000..526951a4 --- /dev/null +++ b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/ReverseArray.cpp @@ -0,0 +1,31 @@ +#include<iostream> +using namespace std; + +void reverse(int* arr, int n){ + int temp,i; + // write your code here + for(i=0;n/2==0?i<=n/2:i<n/2;i++){ + temp = arr[i]; + arr[i]=arr[n-i-1]; + arr[n-i-1]=temp; + } +} + +void display(int* arr, int n){ + for(int i = 0 ; i < n; i++){ + cout<<arr[i]<<" "; + } + cout<<endl; +} + +int main(){ + int n; + cin>>n; + + int arr[n]; + for(int i = 0 ; i < n; i++){ + cin>>arr[i]; + } + reverse(arr,n); + display(arr,n); +} \ No newline at end of file diff --git a/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/RotateAnArray.cpp b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/RotateAnArray.cpp new file mode 100644 index 00000000..d6c73fcb --- /dev/null +++ b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/RotateAnArray.cpp @@ -0,0 +1,41 @@ +#include<iostream> +using namespace std; + +void rotate(int* arr, int n, int k){ + int b[n],c[n]; + k=k%n; + int i,j=0; + if(k<0) + k=n+k; + + for(i=k;i<n;i++) + { + c[i]=arr[j++]; + } + for(i=0;i<k;i++) + { + c[i]=arr[j++]; + } + for(i=0;i<n;i++) + arr[i]=c[i]; +} + +void display(int* arr, int n){ + for(int i = 0 ; i < n; i++){ + cout<<arr[i]<<" "; + } + cout<<endl; +} + +int main(){ + int n, r; + cin>>n; + int* arr = new int[n]; + for(int i = 0 ; i < n; i++){ + cin>>arr[i]; + } + cin>>r; + + rotate(arr,n,r); + display(arr,n); +} \ No newline at end of file diff --git a/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/RotateArray.cpp b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/RotateArray.cpp new file mode 100644 index 00000000..22228879 --- /dev/null +++ b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/RotateArray.cpp @@ -0,0 +1,38 @@ +#include<iostream> +#include<cmath> +using namespace std; + +void rotate(long int* arr,long int* arr2, int n,int k){ + int i,j=n; + if(k<0) + k+=n; + for(i=k-1;i>=0;i--) + arr2[i] = arr[--j]; + j=0; + for(i=k;i<n;i++) + arr2[i]=arr[j++]; + // write your code here + +} + +void display(long int* arr2, int n){ + for(int i = 0 ; i < n; i++){ + cout<<arr2[i]<<" "; + } + cout<<endl; +} + +int main(){ + int n,k; + cin>>n; + long int arr[n],arr2[n],r; + for(int i = 0 ; i < n; i++){ + cin>>arr[i]; + } + cin>>r; + k = r; + if(r>n || r<(-1 * n)) + k = r % n; + rotate(arr,arr2,n,k); + display(arr2,n); +} \ No newline at end of file diff --git a/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/SpanOfArray.cpp b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/SpanOfArray.cpp new file mode 100644 index 00000000..e9c4bc04 --- /dev/null +++ b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/SpanOfArray.cpp @@ -0,0 +1,20 @@ +#include<iostream> +using namespace std; + +int main(){ + int n,i,num; + cin>>n; + int max = 0, min; + for(i=0;i<n;i++){ + cin>>num; + if(num>max) + max=num; + if(i==0) + min=num; + else if(num<min) + min=num; + } + cout<<max-min<<endl; + //write your code here + +} \ No newline at end of file diff --git a/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/SubarrayProblem.cpp b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/SubarrayProblem.cpp new file mode 100644 index 00000000..7f62015b --- /dev/null +++ b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/SubarrayProblem.cpp @@ -0,0 +1,24 @@ +#include<iostream> +using namespace std; + + +int main(){ + int n,i,j,k; + cin>>n; + int* arr = new int[n]; + for(i = 0 ; i < n; i++) + cin>>arr[i]; + i=0; + while(i<n){ + for(k=i;k<n;k++){ + for(j=i;j<=k;j++) + cout<<arr[j]<<" "; + cout<<endl; + } + i++; + } + + + // write your code here + +} \ No newline at end of file diff --git a/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/SubsetsOfArray.cpp b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/SubsetsOfArray.cpp new file mode 100644 index 00000000..83928456 --- /dev/null +++ b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/SubsetsOfArray.cpp @@ -0,0 +1,37 @@ +#include<iostream> +#include<math.h> +using namespace std; + +int main() +{ + int n,i,k,j,index,m; + cin>>n; + index=pow(2,n); + int a[n],arr[n]; + for(i=0;i<n;i++) + cin>>arr[i]; + int b[n]; + for(i=0;i<index;i++) + { + k=0; + j=i; + for(m=0;m<n;m++) + { + b[m]=j%2; + j=j/2; + } + + for(j=m-1;j>=0;j--) + a[k++]=b[j]; + for(j=0;j<m;j++) + { + if(a[j]==1) + cout<<arr[j]<<"\t"; + else + cout<<"-\t"; + } + + cout<<endl; + } + return 0; +} \ No newline at end of file diff --git a/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/SumOfTwoArrays.cpp b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/SumOfTwoArrays.cpp new file mode 100644 index 00000000..941113e1 --- /dev/null +++ b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/FunctionAndArrays/SumOfTwoArrays.cpp @@ -0,0 +1,38 @@ +#include <iostream> +using namespace std; + +int +main () +{ + int n1, n2, i, j; + cin >> n1; + int a[n1]; + for (i = 0; i < n1; i++) + cin >> a[i]; + cin >> n2; + int b[n2]; + for (i = 0; i < n2; i++) + cin >> b[i]; + int max = (n1 > n2) ? n1 : n2; + int c[max], k = max-1, carry = 0; + for (i = n1-1, j = n2-1; i >= 0 && j >= 0; i--, j--) + { + c[k--] = (a[i] + b[j] + carry) % 10; + carry = (a[i] + b[j] + carry) / 10; + } + while (i >= 0) + { + c[k--] = (a[i--]+carry) %10; + carry = (a[i+1]+carry) /10; + } + while (j >= 0) + { + c[k--] = (b[j--]+carry) %10; + carry = (b[j+1]+ carry) /10; + } + if(carry==1) + cout<<carry<<endl; + for(i=0;i<max;i++) + cout<<c[i]<<endl; + return 0; +} \ No newline at end of file diff --git a/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/GettingStarted/CountDigitsInANumber.cpp b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/GettingStarted/CountDigitsInANumber.cpp new file mode 100644 index 00000000..f24d06ff --- /dev/null +++ b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/GettingStarted/CountDigitsInANumber.cpp @@ -0,0 +1,17 @@ +#include <iostream> +using namespace std; + +int main(int argc, char **argv){ + int n; + cin >> n; + + int d; + + while(n>0){ + n /= 10; + d++; + } + + cout<<d; + +} diff --git a/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/GettingStarted/CuriousCaseBulbs.cpp b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/GettingStarted/CuriousCaseBulbs.cpp new file mode 100644 index 00000000..f6363f2c --- /dev/null +++ b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/GettingStarted/CuriousCaseBulbs.cpp @@ -0,0 +1,11 @@ +#include<iostream> +#include<cmath> +using namespace std; +int main(int argc, char**argv){ + int n; + cin>>n; + + for(int i=1;pow(i,2)<n;i++) + cout<<(int)pow(i,2)<<endl; + return 0; +} diff --git a/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/GettingStarted/DigitsOfANumber.cpp b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/GettingStarted/DigitsOfANumber.cpp new file mode 100644 index 00000000..189145b4 --- /dev/null +++ b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/GettingStarted/DigitsOfANumber.cpp @@ -0,0 +1,20 @@ +#include <iostream> +#include<vector> +using namespace std; + +int main(int argc, char **argv){ + int n, d; + cin >> n; + vector<int> digs; + while(n>0){ + d = n%10; + digs.push_back(d); + n /= 10; + } + + for(int i=digs.size()-1;i>=0;i--){ + cout<<digs[i]<<endl; + } + +} + diff --git a/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/GettingStarted/GCDAndLCM.cpp b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/GettingStarted/GCDAndLCM.cpp new file mode 100644 index 00000000..4ed308fa --- /dev/null +++ b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/GettingStarted/GCDAndLCM.cpp @@ -0,0 +1,38 @@ +#include <iostream> +using namespace std; + +int gcd(int, int); +int lcm(int, int); + +int main(int argc, char **argv){ + int num1, num2; + cin >> num1 >> num2; + + cout<<gcd(num1, num2)<<endl; + cout<<lcm(num1, num2)<<endl; + + return 0; +} + +int gcd(int a, int b){ + int min = a>b?b:a; + + for(int i=min;i>1;i--){ + if(a%i == 0 && b%i == 0) + return i; + } + + return 1; +} + +int lcm(int a, int b){ + int max = a>b?a:b; + int min = a>b?b:a; + + for(int i=1;i<=a*b;i++){ + if((max*i)%min == 0) + return max*i; + } + + return a*b; +} diff --git a/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/GettingStarted/GradingSystem.cpp b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/GettingStarted/GradingSystem.cpp new file mode 100644 index 00000000..6ebc2891 --- /dev/null +++ b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/GettingStarted/GradingSystem.cpp @@ -0,0 +1,19 @@ +#include<iostream> +using namespace std; +int main(int argc, char**argv){ + int marks; + cin>>marks; + + if(marks > 90) + cout<<"excellent"; + else if(marks>80) + cout<<"good"; + else if(marks>70) + cout<<"fair"; + else if(marks>60) + cout<<"meets expectations"; + else + cout<<"below par"; + + +} diff --git a/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/GettingStarted/HelloWorld.cpp b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/GettingStarted/HelloWorld.cpp new file mode 100644 index 00000000..5e8e3b5f --- /dev/null +++ b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/GettingStarted/HelloWorld.cpp @@ -0,0 +1,6 @@ +#include<iostream> + +void main() +{ + cout<<"Hello, World!"; +} \ No newline at end of file diff --git a/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/GettingStarted/InverseOfANumber.cpp b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/GettingStarted/InverseOfANumber.cpp new file mode 100644 index 00000000..938c9271 --- /dev/null +++ b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/GettingStarted/InverseOfANumber.cpp @@ -0,0 +1,29 @@ +#include <iostream> +#include <vector> +#include <math.h> +using namespace std; + +int main(int argc, char **argv){ + int n; + cin >> n; + + vector<int> num; + while(n>0){ + num.push_back(n%10); + n/=10; + } + + int inverse[num.size()]; + + for(int i=0;i<num.size();i++){ + inverse[num[i]-1] = i+1; + } + + n = 0; + + for(int i=num.size()-1;i>=0;i--){ + n = n*10 + inverse[i]; + } + + cout<<n; +} diff --git a/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/GettingStarted/IsANumberPrime.cpp b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/GettingStarted/IsANumberPrime.cpp new file mode 100644 index 00000000..c23f39c8 --- /dev/null +++ b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/GettingStarted/IsANumberPrime.cpp @@ -0,0 +1,26 @@ +#include <iostream> +using namespace std; + +bool is_prime(int n){ + for(int i=2;i<=n/2;i++){ + if(n%i==0) + return false; + } + + return true; +} + +int main(int argc, char **argv){ + int t; + cin >> t; + while(t--){ + int n; + cin>>n; + if(is_prime(n)) + cout<<"prime\n"; + else + cout<<"not prime\n"; + } + + return 0; +} diff --git a/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/GettingStarted/MaxMin2.cpp b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/GettingStarted/MaxMin2.cpp new file mode 100644 index 00000000..1398fa98 --- /dev/null +++ b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/GettingStarted/MaxMin2.cpp @@ -0,0 +1,39 @@ +#include <iostream> +#include <climits> +using namespace std; + +int main(){ + int n; + cin>>n; + int ar[n]; + + for(int i=0;i<n;i++){ + scanf("%d", ar+i); + } + + int max=0, min=0, second_max=0, second_min=0; + + for(int i=0;i<n;i++){ + if(ar[max] < ar[i]) + max = i; + + if(ar[min] > ar[i]) + min = i; + } + + for(int i=0;i<n;i++){ + + if(i == max || i == min) + continue; + + if(ar[second_max] < ar[i]) + second_max = i; + + if(ar[second_min] > ar[i]) + second_min = i; + + } + + cout<<ar[second_max]<<" "<<ar[second_min]; + return 0; +} diff --git a/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/GettingStarted/PrimeFactorisation.cpp b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/GettingStarted/PrimeFactorisation.cpp new file mode 100644 index 00000000..06c781d0 --- /dev/null +++ b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/GettingStarted/PrimeFactorisation.cpp @@ -0,0 +1,21 @@ +#include <iostream> +#include<cmath> +using namespace std; + +int main(int argc, char **argv){ + int n; + cin >> n; + + for(int i=2;i<sqrt(n);i++){ + + while(n%i == 0){ + cout<<i<<" "; + n/=i; + } + } + + if(n>2) + cout<<n; + +} + diff --git a/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/GettingStarted/PrimeFactorisationOfANumber.cpp b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/GettingStarted/PrimeFactorisationOfANumber.cpp new file mode 100644 index 00000000..1ae730a8 --- /dev/null +++ b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/GettingStarted/PrimeFactorisationOfANumber.cpp @@ -0,0 +1,15 @@ +#include <iostream> +using namespace std; +int main(int argc, char **argv){ + int n,i; + cin >> n; + for(i=2;i<=n;i++) + { + while((n%i)==0 && n!=1) + { + cout<<i<<" "; + n=n/i; + } + } + +} diff --git a/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/GettingStarted/PrintAllPrimesTillN.cpp b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/GettingStarted/PrintAllPrimesTillN.cpp new file mode 100644 index 00000000..b828a875 --- /dev/null +++ b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/GettingStarted/PrintAllPrimesTillN.cpp @@ -0,0 +1,22 @@ +#include <iostream> +#include<cmath> +using namespace std; + +bool is_prime(int n){ + for(int i=2;i<=sqrt(n);i++){ + if(n%i==0) + return false; + } + return true; +} + +int main(int argc, char **argv){ + int low, high; + cin >> low >> high; + + for(int i=low;i<=high;i++){ + if(is_prime(i)) + cout<<i<<endl; + } + +} diff --git a/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/GettingStarted/PrintFibonacciNumbersTillN.cpp b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/GettingStarted/PrintFibonacciNumbersTillN.cpp new file mode 100644 index 00000000..ecab1bd1 --- /dev/null +++ b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/GettingStarted/PrintFibonacciNumbersTillN.cpp @@ -0,0 +1,17 @@ +#include <iostream> +using namespace std; + +int main(int argc, char **argv) +{ + int x=0, y=1; + int n; + cin>>n; + + for(int i=0;i<n;i++){ + cout<<x<<endl; + int temp = x+y; + x = y; + y = temp; + } + +} diff --git a/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/GettingStarted/PrintZ.cpp b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/GettingStarted/PrintZ.cpp new file mode 100644 index 00000000..58ce2f8e --- /dev/null +++ b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/GettingStarted/PrintZ.cpp @@ -0,0 +1,28 @@ +#include<iostream> +using namespace std; +int main(int argc, char** agrc){ + + for (int i=0;i<5;i++){ + + if(i == 0 || i == 4) + for(int j=0;j<5;j++){ + cout<<"*"; + } + + else{ + for(int j=0;j<5;j++){ + if(j == 5-i-1){ + cout<<"*"; + } + else{ + cout<<" "; + } + } + } + + cout<<endl; + + } + +} + diff --git a/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/GettingStarted/PythagoreanTriplet.cpp b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/GettingStarted/PythagoreanTriplet.cpp new file mode 100644 index 00000000..773964f6 --- /dev/null +++ b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/GettingStarted/PythagoreanTriplet.cpp @@ -0,0 +1,30 @@ +#include <iostream> +#include <cmath> +using namespace std; + +int main(int argc, char **argv){ + int a,b,c; + cin >> a >> b >> c; + + if(a>b && a>c){ + if(pow(a,2) == pow(b,2)+pow(c,2)) + cout<<"true"; + else + cout<<"false"; + } + + if(b>a && b>c){ + if(pow(b,2) == pow(a,2)+pow(c,2)) + cout<<"true"; + else + cout<<"false"; + } + + if(c>a && c>b){ + if(pow(c,2) == pow(a,2) + pow(b,2)) + cout<<"true"; + else + cout<<"false"; + } + return 0; +} diff --git a/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/GettingStarted/ReverseANumber.cpp b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/GettingStarted/ReverseANumber.cpp new file mode 100644 index 00000000..c958fe98 --- /dev/null +++ b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/GettingStarted/ReverseANumber.cpp @@ -0,0 +1,13 @@ +#include <iostream> +using namespace std; + +int main(int argc, char **argv){ + int n; + cin >> n; + + while(n>0){ + cout<<n%10<<endl; + n/=10; + } + +} diff --git a/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/GettingStarted/RotateANumber.cpp b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/GettingStarted/RotateANumber.cpp new file mode 100644 index 00000000..c1208f81 --- /dev/null +++ b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/GettingStarted/RotateANumber.cpp @@ -0,0 +1,29 @@ +#include <iostream> +#include<cmath> + +using namespace std; +int main(){ + long long n,k; + cin>>n>>k; + + long long temp = n; + long long n_digits = 0; + + while(temp>0){ + n_digits++; + temp/=10; + } + + k = k%n_digits; + if(k<0) + k = n_digits+k; + + + long long split_digs = n%(long long)pow(10, k); + n /= (long long)pow(10, k); + + split_digs *= (long long)pow(10, n_digits-k); + n += split_digs; + + cout<<n; +} diff --git a/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/GettingStarted/TheCuriousCaseOfBenjaminBulbs.cpp b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/GettingStarted/TheCuriousCaseOfBenjaminBulbs.cpp new file mode 100644 index 00000000..63ff2c1b --- /dev/null +++ b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/GettingStarted/TheCuriousCaseOfBenjaminBulbs.cpp @@ -0,0 +1,29 @@ +#include<iostream> +using namespace std; + +int main(int argc, char**argv){ + int n,i,j; + cin>>n; + int a[n+1]={0}; + for(j=1;j<=n;j++) + { + for(i=1;i<=n;i++) + { if(i%j==0) + { + if(a[i]) + a[i]=0; + else + a[i]=1; + } + // cout<<a[i]<<"\t"; + } + // cout<<endl; + } + for(i=1;i<=n;i++) + { + if(a[i]) + cout<<i<<endl; + // count++;} + } + // cout<<count; +} \ No newline at end of file diff --git a/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/Patterns/Pattern1.cpp b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/Patterns/Pattern1.cpp new file mode 100644 index 00000000..3bf25157 --- /dev/null +++ b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/Patterns/Pattern1.cpp @@ -0,0 +1,17 @@ +#include <iostream> +using namespace std; + +int main(int argc, char **argv){ + int n,i,j; + cin >> n; + + for(i=1;i<=n;i++) + { + for( j=1;j<=i;j++) + { + cout<<"*\t"; + } + cout<<endl; + } + +} \ No newline at end of file diff --git a/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/Patterns/Pattern10.cpp b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/Patterns/Pattern10.cpp new file mode 100644 index 00000000..1494236b --- /dev/null +++ b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/Patterns/Pattern10.cpp @@ -0,0 +1,38 @@ +#include <iostream> +using namespace std; + +int main(int argc, char **argv){ + int n; + cin >> n; + int i,j,sp,st,isp; + sp=(n/2)+1; + st=-1; + isp=-1; + for(i=0;i<n;i++) + { + if(i<=n/2) + { + sp--; + st+=2; + if(i!=0) + isp+=2; + } + else + { + sp++; + st-=2; + isp-=2; + } + for(j=0;j<sp;j++) + cout<<"\t"; + cout<<"*\t"; + if(i!=0 && i!=n-1) + { + for(j=0;j<isp;j++) + cout<<"\t"; + cout<<"*"; + } + cout<<endl; + } + +} \ No newline at end of file diff --git a/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/Patterns/Pattern11.cpp b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/Patterns/Pattern11.cpp new file mode 100644 index 00000000..0fcfe9e8 --- /dev/null +++ b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/Patterns/Pattern11.cpp @@ -0,0 +1,16 @@ +#include <iostream> +using namespace std; + +int main(int argc, char **argv){ + int n,i,j,k=1;; + cin >> n; + for(i=0;i<n;i++) + { + for(j=0;j<(i+1);j++) + { + cout<<k++<<"\t"; + } + cout<<endl; + } + +} \ No newline at end of file diff --git a/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/Patterns/Pattern13.cpp b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/Patterns/Pattern13.cpp new file mode 100644 index 00000000..48f883eb --- /dev/null +++ b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/Patterns/Pattern13.cpp @@ -0,0 +1,30 @@ +#include <iostream> +using namespace std; +int fact(int n) +{ + int f=1; + while(n) + { + f*=n; + n--; + } + return f; +} +int nCr(int n,int r) +{ + return fact(n)/(fact(r)*fact(n-r)); +} + +int main(int argc, char **argv){ + int n,i,j,k=1; + cin >> n; + for(i=0;i<n;i++) + { + for(j=0;j<(i+1);j++) + { + cout<<nCr(i,j)<<"\t"; + } + cout<<endl; + } + +} diff --git a/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/Patterns/Pattern14.cpp b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/Patterns/Pattern14.cpp new file mode 100644 index 00000000..1c2d50f8 --- /dev/null +++ b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/Patterns/Pattern14.cpp @@ -0,0 +1,11 @@ +#include<iostream> +using namespace std; +int main(int agrc, char** argv){ + int n,i; + cin >> n; + for(i=1;i<=10;i++) + { + cout<<n<<" * "<<i<<" = "<<n*i<<endl; + } + +} \ No newline at end of file diff --git a/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/Patterns/Pattern15.cpp b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/Patterns/Pattern15.cpp new file mode 100644 index 00000000..1b68410e --- /dev/null +++ b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/Patterns/Pattern15.cpp @@ -0,0 +1,50 @@ +#include <iostream> +using namespace std; +int main(int argc, char**argv){ + int n,i,j,st=1,k; + cin >> n; + int sp=n/2; + for(i=1;i<=n;i++) + { + k=i; + for(j=0;j<sp;j++) + cout<<"\t"; + if(i<=n/2) + { + for(j=0;j<=st/2;j++) + cout<<k++<<"\t"; + k--; + for(j=(st/2)+1;j<st;j++) + { + cout<<--k<<"\t"; + } + } + else{ + k=n+1-i; + for(j=0;j<=st/2;j++) + { + cout<<k<<"\t"; + k++; + } + k--; + for(j=(st/2)+1; j<st;j++) + { + k--; + cout<<k<<"\t"; + + } + + } + cout<<endl; + if(i<=n/2) + { + sp--; + st+=2; + } + else{ + sp++; + st-=2; + } + } + +} \ No newline at end of file diff --git a/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/Patterns/Pattern16.cpp b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/Patterns/Pattern16.cpp new file mode 100644 index 00000000..07fa36a9 --- /dev/null +++ b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/Patterns/Pattern16.cpp @@ -0,0 +1,25 @@ +#include <iostream> +using namespace std; +int main(int argc, char**argv){ + int n,i,j; + cin >> n; + + for(i=1;i<=n;i++) + { + for(j=1;j<=(2*n-1);j++) + { + if(j<=i || j>= (2*n-i)) + { + if(j<=i) + cout<<j<<"\t"; + else + cout<<2*n-j<<"\t"; + } + else + cout<<"\t"; + } + cout<<endl; + } + + +} \ No newline at end of file diff --git a/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/Patterns/Pattern17.cpp b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/Patterns/Pattern17.cpp new file mode 100644 index 00000000..b3427db1 --- /dev/null +++ b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/Patterns/Pattern17.cpp @@ -0,0 +1,33 @@ +#include <iostream> +using namespace std; +int main(int agrc, char**argv){ + int n,i,j,st=1,sp; + cin >> n; + sp=n/2; + for(i=1;i<=n;i++) + { + for(j=1;j<=sp;j++) + { + cout<<"\t"; + } + for(j=1;j<=st;j++) + { + if(j<=st/2 && i!=(n/2)+1 ) + cout<<"\t"; + else + cout<<"*\t"; + } + cout<<endl; + if(i<= n/2) + { + sp--; + st+=2; + } + else{ + sp++; + st-=2; + } + + } + +} \ No newline at end of file diff --git a/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/Patterns/Pattern18.cpp b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/Patterns/Pattern18.cpp new file mode 100644 index 00000000..55b5cb28 --- /dev/null +++ b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/Patterns/Pattern18.cpp @@ -0,0 +1,38 @@ +#include <iostream> +using namespace std; +int main(int agrc, char**argv){ + int n,i,j; + cin >> n; + int sp=-1,st=n+2; + for(i=0;i<n;i++) + { + if(i<=n/2) + { + st-=2; + sp++; + } + else + { + st+=2; + sp--; + } + if(i>0 && i<n/2) + { + for(j=0;j<sp;j++) + cout<<"\t"; + cout<<"*\t"; + for(j=0;j<st-2;j++) + cout<<"\t"; + cout<<"*\t"; + } + else{ + for(j=0;j<sp;j++) + cout<<"\t"; + for(j=0;j<st;j++) + cout<<"*\t"; + } + cout<<endl; + + } + +} \ No newline at end of file diff --git a/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/Patterns/Pattern19.cpp b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/Patterns/Pattern19.cpp new file mode 100644 index 00000000..c9e03077 --- /dev/null +++ b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/Patterns/Pattern19.cpp @@ -0,0 +1,28 @@ +#include <iostream> +using namespace std; +int main(int argc, char** argv){ + int n,i,j; + cin >> n; + for(i=1;i<=n;i++) + { + for(j=1;j<=n;j++) + { + if(i==1 && (j<= (n+1)/2 || j==n)) + cout<<"*"<<"\t"; + else if(i==n && (j >= (n+1)/2 || j==1)) + cout<<"*\t"; + else if(j==(n+1)/2 || i==(n+1)/2) + cout<<"*\t"; + else if(i<=(n+1)/2 && j==n) + cout<<"*\t"; + else if(i>=(n+1)/2 && j==1) + cout<<"*\t"; + else + cout<<"\t"; + + + } + cout<<endl; + } + +} \ No newline at end of file diff --git a/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/Patterns/Pattern2.cpp b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/Patterns/Pattern2.cpp new file mode 100644 index 00000000..0b914cc6 --- /dev/null +++ b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/Patterns/Pattern2.cpp @@ -0,0 +1,20 @@ +#include <iostream> +using namespace std; + +int main(int argc, char **argv){ + int n,i,j,k; + cin >> n; + k=n; + for(i=1;i<=n;i++) + { + for(j=1;j<=k;j++) + { + cout<<"*\t"; + + } + cout<<endl; + k--; + } + + +} \ No newline at end of file diff --git a/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/Patterns/Pattern20.cpp b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/Patterns/Pattern20.cpp new file mode 100644 index 00000000..03c70195 --- /dev/null +++ b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/Patterns/Pattern20.cpp @@ -0,0 +1,34 @@ +#include <iostream> +using namespace std; +int main(int argc, char**argv){ + int n,i,j,k,m,o; + cin >> n; + k=(n+1)/2; + m=k; + o=k; + for(i=1;i<=n;i++) + { + for(j=1;j<=n;j++) + { + if(j==1 || j==n) + cout<<"*\t"; + else if(i>=k && (j==m || j==o)) + { + cout<<"*\t"; + } + + else + cout<<"\t"; + + } + cout<<endl; + if(i>=k) + { + m++; + o--; + } + } + + + +} \ No newline at end of file diff --git a/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/Patterns/Pattern3.cpp b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/Patterns/Pattern3.cpp new file mode 100644 index 00000000..6b7d051e --- /dev/null +++ b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/Patterns/Pattern3.cpp @@ -0,0 +1,20 @@ +#include <iostream> +using namespace std; + +int main(int argc, char **argv){ + int n,i,j; + cin >> n; + + for(i=1;i<=n;i++) + { + for(j=1;j<=n;j++) + { + if((i+j)>n) + cout<<"*\t"; + else + cout<<"\t"; + } + cout<<endl; + } + +} \ No newline at end of file diff --git a/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/Patterns/Pattern4.cpp b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/Patterns/Pattern4.cpp new file mode 100644 index 00000000..62c33d87 --- /dev/null +++ b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/Patterns/Pattern4.cpp @@ -0,0 +1,21 @@ +#include <iostream> +using namespace std; + +int main(int argc, char **argv){ + int n,i,j,m; + cin >> n; + m=0; + for(i=1;i<=n;i++) + { + for(j=1;j<=n;j++) + { + if(j<=m) + cout<<"\t"; + else + cout<<"*\t"; + } + cout<<endl; + m++; + } + +} \ No newline at end of file diff --git a/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/Patterns/Pattern5.cpp b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/Patterns/Pattern5.cpp new file mode 100644 index 00000000..7938be64 --- /dev/null +++ b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/Patterns/Pattern5.cpp @@ -0,0 +1,39 @@ +#include <iostream> +using namespace std; + +int main(int argc, char **argv){ + int n,i,j,k,m; + cin >> n; + k=n/2; + for(i=1;i<=n/2;i++) + { + + m=(2*i)-1; + for(j=1;j<=k;j++) + cout<<"\t"; + for(j=1;j<=m;j++) + cout<<"*\t"; + cout<<endl; + k--; + } + for(i=0;i<n;i++) + { + cout<<"*\t"; + } + cout<<endl; + k=1; + for(i=1;i<=n/2;i++) + { + + + for(j=1;j<=k;j++) + cout<<"\t"; + for(j=1;j<=m;j++) + cout<<"*\t"; + cout<<endl; + k++; + m-=2; + } + + +} \ No newline at end of file diff --git a/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/Patterns/Pattern6.cpp b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/Patterns/Pattern6.cpp new file mode 100644 index 00000000..d0a6af48 --- /dev/null +++ b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/Patterns/Pattern6.cpp @@ -0,0 +1,29 @@ +#include <iostream> +using namespace std; + +int main(int argc, char **argv){ + int n,i,j,st,sp; + cin >> n; + st=((n+1)/2)+1; + sp=-1; + for(i=0;i<n;i++) + { + if(i<(n+1)/2) + { + st--; + sp+=2; + } + else + { + sp-=2; + st++; + } + for(j=0;j<st;j++) + cout<<"*\t"; + for(j=0;j<sp;j++) + cout<<"\t"; + for(j=0;j<st;j++) + cout<<"*\t"; + cout<<endl; + } +} \ No newline at end of file diff --git a/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/Patterns/Pattern7.cpp b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/Patterns/Pattern7.cpp new file mode 100644 index 00000000..efab6411 --- /dev/null +++ b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/Patterns/Pattern7.cpp @@ -0,0 +1,20 @@ +#include <iostream> +using namespace std; + +int main(int argc, char **argv){ + int n,i,j; + cin >> n; + + for(i=1;i<=n;i++) + { + for(j=1;j<=n;j++) + { + if(i==j) + cout<<"*\t"; + else + cout<<"\t"; + } + cout<<endl; + } + +} \ No newline at end of file diff --git a/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/Patterns/Pattern8.cpp b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/Patterns/Pattern8.cpp new file mode 100644 index 00000000..410823fe --- /dev/null +++ b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/Patterns/Pattern8.cpp @@ -0,0 +1,21 @@ +#include <iostream> +using namespace std; + +int main(int argc, char **argv) +{ + int n,i,j; + cin >> n; + for(i=1;i<=n;i++) + { + for(j=1;j<=n;j++) + { + if(i+j==n+1) + cout<<"*\t"; + else + cout<<"\t"; + } + cout<<endl; + } + + +} \ No newline at end of file diff --git a/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/Patterns/Pattern9.cpp b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/Patterns/Pattern9.cpp new file mode 100644 index 00000000..79080650 --- /dev/null +++ b/IOT/kishanpriya169_PiyaKishan_2024ec1096_2/Patterns/Pattern9.cpp @@ -0,0 +1,20 @@ +#include <iostream> +using namespace std; + +int main(int argc, char **argv){ + int n,i,j; + cin >> n; + + for(i=1;i<=n;i++) + { + for(j=1;j<=n;j++) + { + if(i==j || (i+j)==(n+1)) + cout<<"*\t"; + else + cout<<"\t"; + } + cout<<endl; + } + +} \ No newline at end of file