Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Completed 10 more questions in the module Patterns #196

Merged
merged 6 commits into from
Oct 11, 2022
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <iostream>
using namespace std;

int main(int argc, char **argv){
int n,k;
cin >> n;
while(n!=0){
n=n/10;
k++;
}
cout<<k;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <iostream>
#include <cmath>
using namespace std;

int main(int argc, char **argv){
long long int n,r,rev=0,d,t;
cin >> n;
t=n;

while(n!=0){
r=n%10;
rev=rev*10 + r;
n=n/10;
}

while(rev!=0){
d=rev%10;
cout<<d<<endl;
rev=rev/10;
}
while(t%10==0){
cout<<"0"<<endl;
t=t/10;

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <iostream>
using namespace std;
int main(int argc, char **argv){
int num1, num2;
cin >> num1 >> num2;
int low,k=0;
if(num1>num2)
low=num2;
else
low=num1;
int gcd[low/2];
for(int i=1;i<=low;i++){
if(num1%i==0 && num2%i==0){
gcd[k]=i;
k++;
}
}
cout<<gcd[k-1]<<endl<<((num1*num2)/gcd[k-1]);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include<iostream>
using namespace std;
int main(int argc, char**argv){
int marks;
cin>>marks;
if(marks>90)
cout<<"excellent";
else if(marks<=90 && marks>80)
cout<<"good";
else if(marks<=80 && marks>70)
cout<<"fair";
else if(marks<=70 && marks>60)
cout<<"meets expectations";
else if(marks<=60)
cout<<"below par";

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <iostream>
#include <math.h>
using namespace std;

int main(int argc, char **argv){
int n,i=1,c,sum=0;
cin >> n;
while(n!=0){
c=n%10;

sum = sum + i*pow(10,c-1) ;
n=n/10;
i++;
}
cout<<sum;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <iostream>
using namespace std;
int main(int argc, char **argv){
int t,k;
cin >> t;
int n;
for(int i=0;i<t;i++){
cin>>n;
for(int j=2;j<=n;j++){
if(n%j==0)
k++;
}
if(k>=2 )
cout<<"not prime\n";
else
cout<<"prime\n";
k=0;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <iostream>
using namespace std;
int main(int argc, char **argv){
int n;
cin >> n;
int i=2;
while(n!=1){
if(n%i==0){
cout<<i<<" ";
n=n/i;
}
if(n%i!=0){
i++;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <iostream>
#include<cmath>
using namespace std;
int main(int argc, char **argv){
int low, high,k=0,i;
cin >> low >> high;
for(int i=low;i<=high;i++){

for(int j=2;j<=sqrt(i);j++){
if(i%j==0)
k++;
}
if(k==0 )
cout<< i<<endl;

k=0;
}

return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <iostream>
using namespace std;
int fibo(int n);

int main(int argc, char **argv)
{
int n;
cin >> n;
for(int i=0;i<n;i++){
cout<<fibo(i)<<endl;
}

}
int fibo(int n){
if(n==0)
return 0;
else if(n==1)
return 1;
else
return(fibo(n-2)+fibo(n-1));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include<iostream>
using namespace std;
int main(int argc, char** agrc) {
cout << "*****" << endl;
cout << " *" << endl;
cout << " *" << endl;
cout << " *" << endl;
cout << "*****" << endl;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include <iostream>
using namespace std;

int main(int argc, char **argv){
long long int n,d,t,rev=0,r;
cin >> n;
t=n;
while(n!=0){
d=n%10;
cout<<d<<endl;
n=n/10;

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include <iostream>
#include<cmath>
using namespace std;
int main(){
int n,k,i=1,t;
cin>>n>>k;
int digits = 0;
t=n;
while(t != 0){
t = t/10;
digits++;
}
int c[digits];
if(k>0){
if(k>digits){
k=k%digits;
}
while(i<=k){
c[i] = n%10;
n=n/10;
i++;
}
while(i>1){
cout<<c[i-1];
i--;
}
if(n>0)
cout<<n;
}
else if(k<0){
k=-k;
if(k>digits){
k=k%digits;
}
while(i<=(digits-k)){
c[i] = n%10;
n=n/10;
i++;
}
while(i>1){
cout<<c[i-1];
i--;
}
if(n>0)
cout<<n;
}
else
cout<<n;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include<iostream>
using namespace std;
int main(int argc, char**argv){
int n;
cin>>n;
for(int i=1; i*i<=n;i++){
cout<<i*i<<endl;
}
}
14 changes: 14 additions & 0 deletions IOT/ritikgupta88_RitikGupta_2125csit1163_2/Patterns/Pattern1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include <iostream>
using namespace std;

int main(int argc, char **argv){
int n;
cin >> n;
for(int i=0;i<n;i++){
for(int j=0;j<=i;j++){
if(i+j<=2*i)
cout<<"*\t";
}
cout<<endl;
}
}
32 changes: 32 additions & 0 deletions IOT/ritikgupta88_RitikGupta_2125csit1163_2/Patterns/Pattern10.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include <iostream>
using namespace std;

int main(int argc, char **argv){
int n;
cin >> n;
for(int i=0;i<(n/2)+1;i++){
for(int j=0;j<n;j++){
if(i+j==n/2|| j==n/2+i)
cout<<"*\t";
else
cout<<"\t";

}
cout<<endl;

}

for(int i=(n/2)-1;i>=0;i--){
for(int j=0;j<n;j++){
if(i+j==n/2|| j==n/2+i)
cout<<"*\t";
else
cout<<"\t";

}
cout<<endl;

}


}
19 changes: 19 additions & 0 deletions IOT/ritikgupta88_RitikGupta_2125csit1163_2/Patterns/Pattern11.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <iostream>
using namespace std;

int main(int argc, char **argv){
int n,k=1;
cin >> n;
for(int i=0;i<n;i++){
for(int j=0;j<=i;j++){
if(i+j<=2*i){
cout<<k<<"\t";
k++;
}
}
cout<<endl;
}

//write your code here

}
28 changes: 28 additions & 0 deletions IOT/ritikgupta88_RitikGupta_2125csit1163_2/Patterns/Pattern12.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include <iostream>
using namespace std;
int fibo(int n);
int main(int argc, char **argv){
int n,k=1;
cin >> n;
for(int i=0;i<n;i++){
for(int j=0;j<=i;j++){
if(i+j<=2*i){
cout<<fibo(k)<<"\t";
k++;
}
}
cout<<endl;
}
}
int fibo(int n){
if(n==1 )
return 0;
if(n==2)
return 1;

else
return(fibo(n-1)+fibo(n-2));

//write your code here

}
23 changes: 23 additions & 0 deletions IOT/ritikgupta88_RitikGupta_2125csit1163_2/Patterns/Pattern13.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

#include <iostream>
using namespace std;

int main(int argc, char **argv){
int n;
cin >> n;
int arr[n][n];
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(i==j || j==0){
arr[i][j]= 1 ;
cout<<"1\t";
}
else if(j>0 && j<i){
arr[i][j]=(arr[i-1][j-1] + arr[i-1][j]);
cout<<arr[i][j]<<'\t';
}

}
cout<<endl;
}
}
Loading