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/BarChart.cpp b/IOT/gurpreetk12_gurpreetkaur_2125cs1094_2/FunctionandArrays/BarChart.cpp new file mode 100644 index 00000000..7f38622c --- /dev/null +++ b/IOT/gurpreetk12_gurpreetkaur_2125cs1094_2/FunctionandArrays/BarChart.cpp @@ -0,0 +1,35 @@ +#include +using namespace std; +int main() +{ + int n; + cin>>n; + int arr[n]; + for(int i=0;i>arr[i]; + } + int max=arr[0]; + for(int i=0;i=max) + { + max=arr[i]; + } + } + for(int i=max;i>0;i--) + { + for(int j=0;j=i) + { + cout<<"*\t"; + } + else + { + cout<<"\t"; + } + + }cout<<"\n"; + } +} \ No newline at end of file diff --git a/IOT/gurpreetk12_gurpreetkaur_2125cs1094_2/FunctionandArrays/DecimalToAnyBase.cpp b/IOT/gurpreetk12_gurpreetkaur_2125cs1094_2/FunctionandArrays/DecimalToAnyBase.cpp new file mode 100644 index 00000000..bf2dfe3d --- /dev/null +++ b/IOT/gurpreetk12_gurpreetkaur_2125cs1094_2/FunctionandArrays/DecimalToAnyBase.cpp @@ -0,0 +1,29 @@ +#include +#include +using namespace std; +int DecToAny(int n, int b) { + int arr[100],i=0,f=0,final; + while(n!=0) + { + int q=n%b; + arr[i]=q; + i++; + n=n/b; + } + for(int j=i-1;j>=0;j--) + { + int g=pow(10,j); + int final=arr[j]*g; + f=f+final; + } + return f; + +} +int main() { + int n; + int b; + cin >> n; + cin >> b; + int res = DecToAny(n, b); + cout << res << endl; +} \ No newline at end of file diff --git a/IOT/gurpreetk12_gurpreetkaur_2125cs1094_2/FunctionandArrays/DigitFrequency.cpp b/IOT/gurpreetk12_gurpreetkaur_2125cs1094_2/FunctionandArrays/DigitFrequency.cpp new file mode 100644 index 00000000..4c67f71c --- /dev/null +++ b/IOT/gurpreetk12_gurpreetkaur_2125cs1094_2/FunctionandArrays/DigitFrequency.cpp @@ -0,0 +1,23 @@ +#include +using namespace std; +int digFreq(int n, int d) { + int arr[100],i=0,c=0; + while(n!=0) + { + arr[i]=n%10; + n=n/10; + i++; + } + for(int j=0;j> n >> d; + int res = digFreq(n, d); + cout << res << endl; +} \ No newline at end of file diff --git a/IOT/gurpreetk12_gurpreetkaur_2125cs1094_2/FunctionandArrays/FindElementInAnArray.cpp b/IOT/gurpreetk12_gurpreetkaur_2125cs1094_2/FunctionandArrays/FindElementInAnArray.cpp new file mode 100644 index 00000000..e8a0f950 --- /dev/null +++ b/IOT/gurpreetk12_gurpreetkaur_2125cs1094_2/FunctionandArrays/FindElementInAnArray.cpp @@ -0,0 +1,30 @@ +#include +using namespace std; + +int main(){ + int n,c=0; + cin>>n; + int arr[n]; + for(int i=0;i +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/SpanOfArray.cpp b/IOT/gurpreetk12_gurpreetkaur_2125cs1094_2/FunctionandArrays/SpanOfArray.cpp new file mode 100644 index 00000000..ff274422 --- /dev/null +++ b/IOT/gurpreetk12_gurpreetkaur_2125cs1094_2/FunctionandArrays/SpanOfArray.cpp @@ -0,0 +1,29 @@ +#include +using namespace std; + +int main(){ + int n; + cin>>n; + int arr[n],e; + for(int i=0;i>e; + arr[i]=e; + } + int max=arr[0],min=arr[0]; + for(int i=0;i=max) + { + max=arr[i]; + } + if(arr[i]<=min) + { + min=arr[i]; + } + } + int sum=max-min; + cout< +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< +using namespace std; +int main(int argc, char**argv){ + int marks; + cin>>marks; + if(marks>90) + cout<<"excellent"; + else if(marks>80&&marks<=90) + cout<<"good"; + else if(marks>70&&marks<=80) + cout<<"fair"; + else if(marks>60&&marks<=70) + cout<<"expectations"; + else + cout<<"below par"; + +} \ No newline at end of file diff --git a/IOT/gurpreetk12_gurpreetkaur_2125cs1094_2/Gettingstarted/IsANumberPrime.cpp b/IOT/gurpreetk12_gurpreetkaur_2125cs1094_2/Gettingstarted/IsANumberPrime.cpp new file mode 100644 index 00000000..7f62cef1 --- /dev/null +++ b/IOT/gurpreetk12_gurpreetkaur_2125cs1094_2/Gettingstarted/IsANumberPrime.cpp @@ -0,0 +1,32 @@ +#include +using namespace std; +int main(int argc, char **argv){ + int t,i=0; + cin >> t; + while(i!=t) + { + int n,c=0; + cin>>n; + for(int i=2;i<=(n/2);i++) + { + if(n%i==0) + { + c++; + break; + } + else + { + continue; + } + } + if(c!=0) + { + cout<<"not prime"< +using namespace std; +int main() +{ + int l,u,c=0; + cin>>l; + cin>>u; + while(l!=u) + { c=0; + for(int i=2;i<=(l/2);i++) + { + if(l%i==0) + { + c++; + break; + } + else + { + continue; + } + } + if(c==0) + { + cout< +using namespace std; +int main() +{ + for(int i=1;i<=5;i++) + { + if(i==1||i==5) + { + for(int j=1;j<=5;j++) + { + cout<<"*"; + }cout< +using namespace std; + +int main(int argc, char **argv){ + int n,i=0; + cin >> n; + while(n!=0) + { + n=n/10; + i++; + }cout< +using namespace std; + +int main(int argc, char **argv){ + int n,arr[100],i=0,q; + cin >> n; + while(n!=0) + { + q=n%10; + n=n/10; + arr[i]=q; + i++; + } + for(int j=i-1;j>=0;j--) + { + cout< +using namespace std; + +int main(int argc, char **argv){ + int n,a; + cin >> n; + while(n!=0) + { + a=n%10; + cout< + +using namespace std; + +int main() +{ + int n,i,j,k,l; + cin>>n; + for(i=1;i<=n;i++) + { + for(j=1;j<=n;j++) + { + if(j==1 || j==n) + cout<<"*\t"; + else if(i>n/2 && ( i==j || (i+j)==n+1)) + cout<<"*\t"; + else + cout<<"\t"; + } + cout< +using namespace std; + +int main(int argc, char **argv){ + int n; + cin >> n; + for(int i=1;i<=n;i++) + { + for(int j=1;j<=i;j++) + { + cout<<"*\t"; + }cout< +using namespace std; +int main() +{ + int n; + cin>>n; + int q=n/2; + q++; + for(int i=0;i + +using namespace std; + +int main() +{ + int n,j=1; + cin>>n; + for(int i=1;i<=n;i++) + { + for(int k=1;k<=i;k++) + { + cout< + +using namespace std; + +int main() +{ + int n,j=1,var=1,a=1; + cin>>n; + for(int i=1;i<=n;i++) + { + if(i==1) + { + cout<<"0"; + cout<<"\n"; + continue; + } + if(i==2) + { + cout<<"1"<<"\t"<<"1"; + } + else + { + for(int k=1;k<=i;k++) + { + var=a+j; + cout< +using namespace std; + +int main(int argc, char **argv){ + int n; + cin >> n; + + for (int i = 0; i < n; i++){ + int val = 1; + for (int j = 0; j <= i; j++){ + cout << val << ("\t"); + val = (val * (i - j)) / (j + 1); + } + cout << endl; + } +} + + \ No newline at end of file diff --git a/IOT/gurpreetk12_gurpreetkaur_2125cs1094_2/Patterns/Pattern14.cpp b/IOT/gurpreetk12_gurpreetkaur_2125cs1094_2/Patterns/Pattern14.cpp new file mode 100644 index 00000000..15b942e6 --- /dev/null +++ b/IOT/gurpreetk12_gurpreetkaur_2125cs1094_2/Patterns/Pattern14.cpp @@ -0,0 +1,14 @@ +#include + +using namespace std; + +int main() +{ + int n; + cin>>n; + for(int i=1;i<=10;i++) + { + cout< +using namespace std; + +int main() +{ + int n,q,m=0; + cin>>n; + q=n/2; + q++; + for(int i=0;ii+1) + { + for(int k=1;k<=i;k++) + { + cout<0;i--) + { + for(int j=2;j<=c;j++) + { + cout<<"\t"; + } + for(int j=1;j<=2*i-1;j++) + { + if(j>i) + { + if(m-h>=i) + {cout< +using namespace std; +int main() +{ + int n; + cin>>n; + int b=n; + int q=2*b+3; + for(int i=1;i<=n;i++) + { + q=2*b-3; + if(q<0) + { + for(int j=1;j<=i;j++) + { + cout<=1;j--) + { + cout<=1;j--) + { + cout< +using namespace std; +int main() +{ + int n; + cin>>n; + int c=1; + int q=n/2; + for(int i=1;i<=n;i++) + { + if(iq+1) + { + for(int j=1;j<=q;j++) + { + cout<<"\t"; + } + for(int k=1;k<=q+1-c;k++) + { + cout<<"*"<<"\t"; + }c++; + } + cout<<"\n"; + } +} \ No newline at end of file diff --git a/IOT/gurpreetk12_gurpreetkaur_2125cs1094_2/Patterns/Pattern18.cpp b/IOT/gurpreetk12_gurpreetkaur_2125cs1094_2/Patterns/Pattern18.cpp new file mode 100644 index 00000000..7253868b --- /dev/null +++ b/IOT/gurpreetk12_gurpreetkaur_2125cs1094_2/Patterns/Pattern18.cpp @@ -0,0 +1,43 @@ +#include +using namespace std; +int main() +{ + int n; + cin>>n; + int q=n/2; + int q1=q+1; + for(int i=1;i<=n;i++) + { + cout<<"*"<<"\t"; + }cout<<"\n"; + for(int i=1;i<=q;i++) + { + for(int j=1;j<=i;j++) + { + cout<<"\t"; + } + cout<<"*"<<"\t"; + int g=2*i; + for(int j=1;j<=(n-g-2);j++) + { + cout<<"\t"; + } + if(i!=q) + { + cout<<"*"; + } + + cout<<"\n"; + } + for(int i=0;i +using namespace std; +int main() +{ + int n; + cin>>n; + int q=n/2; + q++; + for(int i=1;i<=q;i++) + { + if(i==1) + { + for(int j=1;j<=q;j++) + { + cout<<"*"<<"\t"; + } + for(int j=1;j +using namespace std; + +int main(){ + int n; + cin >> n; + for(int i=0;i=1+i;j--) + { + cout<<"*\t"; + }cout< +using namespace std; + +int main(int argc, char **argv){ + int n; + cin >> n; + for(int i=1;i<=n;i++) + { + for(int j=n;j>i;j--) + { + cout<<"\t"; + } + for(int j=1;j<=i;j++) + { + cout<<"*\t"; + }cout< +using namespace std; + +int main(int argc, char **argv){ + int n; + cin >> n; + for(int i=0;i +using namespace std; + +int main(int argc, char **argv){ + int n,c=0; + cin >> n; + int d=(n-1)/2; + for(int i=1;i<=n;i++) + { + if(c + +using namespace std; + +int main() +{ + int n; + cin>>n; + int q=n/2; + q++; + for(int i=0;i +using namespace std; + +int main(int argc, char **argv){ + int n; + cin >> n; + for(int i=0;i +using namespace std; + +int main(int argc, char **argv) +{ + int n; + cin >> n; + for(int i=n;i>=1;i--) + { + for(int j=1;j +using namespace std; + +int main(int argc, char **argv){ + int n; + cin >> n; + + for (int i = 1; i <= n; i++){ + for (int 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