diff --git a/IOT/gurpreetk12_gurpreetkaur_2125cs1094_2/FunctionandArrays/AnyBaseToDecimal.cpp b/IOT/gurpreetk12_gurpreetkaur_2125cs1094_2/FunctionandArrays/AnyBaseToDecimal.cpp new file mode 100644 index 00000000..4f330ecc --- /dev/null +++ b/IOT/gurpreetk12_gurpreetkaur_2125cs1094_2/FunctionandArrays/AnyBaseToDecimal.cpp @@ -0,0 +1,28 @@ +#include +#include +using namespace std; +int AnyToDec(int n, int b) { + int g=n; + int p=0,i=0,sum=0; + int q=g; + while(g!=0) + { + q=g%10; + p=pow(b,i); + + i++; + g=g/10; + sum=sum+(p*q); + } + return(sum); + +} +int main() { + int n; + int b; + int sum=0,h=0,g=0,i=0; + cin >> n; + cin >> b; + int res = AnyToDec(n, b); + cout << res << endl; +} \ No newline at end of file diff --git a/IOT/gurpreetk12_gurpreetkaur_2125cs1094_2/FunctionandArrays/Inverseofanarray.cpp b/IOT/gurpreetk12_gurpreetkaur_2125cs1094_2/FunctionandArrays/Inverseofanarray.cpp new file mode 100644 index 00000000..73ba4c99 --- /dev/null +++ b/IOT/gurpreetk12_gurpreetkaur_2125cs1094_2/FunctionandArrays/Inverseofanarray.cpp @@ -0,0 +1,31 @@ +#include +using namespace std; + +int* inverse(int* arr, int n){ + for(int i=0;i>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/gurpreetk12_gurpreetkaur_2125cs1094_2/FunctionandArrays/ReverseAnArray.cpp b/IOT/gurpreetk12_gurpreetkaur_2125cs1094_2/FunctionandArrays/ReverseAnArray.cpp new file mode 100644 index 00000000..8867e5fe --- /dev/null +++ b/IOT/gurpreetk12_gurpreetkaur_2125cs1094_2/FunctionandArrays/ReverseAnArray.cpp @@ -0,0 +1,20 @@ +#include +using namespace std; + +void reverse(int* arr, int n){ + for(int i=n-1;i>=0;i--) + { + cout<>n; + + int* arr = new int[n]; + for(int i = 0 ; i < n; i++){ + cin>>arr[i]; + } + reverse(arr,n); +} \ No newline at end of file diff --git a/IOT/gurpreetk12_gurpreetkaur_2125cs1094_2/FunctionandArrays/RotateAnArray.cpp b/IOT/gurpreetk12_gurpreetkaur_2125cs1094_2/FunctionandArrays/RotateAnArray.cpp new file mode 100644 index 00000000..21863b40 --- /dev/null +++ b/IOT/gurpreetk12_gurpreetkaur_2125cs1094_2/FunctionandArrays/RotateAnArray.cpp @@ -0,0 +1,72 @@ +#include +using namespace std; + +void rotate(int* arr, int n, int k){ + int r=k; + if(r>0) + { + if(r>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/gurpreetk12_gurpreetkaur_2125cs1094_2/FunctionandArrays/SumOfTwoArrays.cpp b/IOT/gurpreetk12_gurpreetkaur_2125cs1094_2/FunctionandArrays/SumOfTwoArrays.cpp new file mode 100644 index 00000000..eae054a9 --- /dev/null +++ b/IOT/gurpreetk12_gurpreetkaur_2125cs1094_2/FunctionandArrays/SumOfTwoArrays.cpp @@ -0,0 +1,55 @@ +#include +using namespace std; + +int main(){ + int n1, n2; + cin>>n1; + int* a1 = new int[n1]; + for(int i = 0 ; i < n1; i++){ + cin>>a1[i]; + } + + cin>>n2; + int* a2 = new int[n2]; + for(int i = 0 ; i < n2; i++){ + cin>>a2[i]; + } + + int m = max(n1,n2); + int* ans = new int[m]; + + int i = n1 - 1; + int j = n2 - 1; + int k = m - 1; + int carry = 0; + + while(k >= 0){ + int sum = carry; + if(i >= 0){ + sum += a1[i]; + } + + if(j >= 0){ + sum += a2[j]; + } + + int q = sum / 10; + int r = sum % 10; + + ans[k] = r; + carry = q; + i--; + j--; + k--; + } + + if(carry != 0){ + cout<