Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
886 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
|
||
#include <stdio.h> | ||
int binarySearch(int arr[], int l, int r, int no) | ||
{ | ||
if (r >= l) | ||
{ | ||
int mid = l + (r - l)/2; | ||
|
||
if (arr[mid] == no) | ||
return mid; | ||
|
||
if (arr[mid] > no){ | ||
printf("B:%d\nA:You're too high\n",arr[mid]); | ||
return binarySearch(arr, l, mid-1, no);} | ||
|
||
|
||
else{ | ||
printf("B:%d\nA:You're too low\n",arr[mid]); | ||
return binarySearch(arr, mid+1, r, no);} | ||
} | ||
|
||
return -1; | ||
} | ||
|
||
int main(void) | ||
{ | ||
int arr[100],no; | ||
for(int i=0;i<100;i++){ | ||
arr[i]=i+1; | ||
} | ||
printf("A:Choose your secret number between 1 and 100:"); | ||
scanf("%d",&no); | ||
int n = sizeof(arr)/ sizeof(arr[0]); | ||
|
||
int result = binarySearch(arr, 0, n-1, no); | ||
(result == -1)? printf("Element is not present ") | ||
: printf("B:Your secret number is: %d", | ||
result+1); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#include <iostream> | ||
#include <algorithm> | ||
using namespace std; | ||
|
||
int prop(int a1[], int a2[]) | ||
{ | ||
sort(a1,a1+3); | ||
sort(a2,a2+3); | ||
|
||
if(a1[0]==a2[0] && a1[1]==a2[1] && a1[2]==a2[2]) | ||
return 1; | ||
else | ||
return 0; | ||
|
||
} | ||
int sideangle(int s1[], int s2[],int a1[],int a2[]) | ||
{ | ||
sort(a1,a1+3); | ||
sort(a2,a2+3); | ||
sort(s1,s1+3); | ||
sort(s2,s2+3); | ||
if( s1[0]/s2[0]==s1[1]/s2[1]){ | ||
if (a1[2]==a2[2]) | ||
return 1;} | ||
if (s1[1]/s2[1]==s1[2]/s2[2]){ | ||
if(a1[0]==a2[0]) | ||
return 1;} | ||
if(s1[2]/s2[2]==s1[0]/s2[0]){ | ||
if(a1[1]==a2[1]) | ||
return 1;} | ||
return 0; | ||
} | ||
|
||
int sides(int s1[],int s2[]) | ||
{ | ||
sort(s1,s1+3); | ||
sort(s2,s2+3); | ||
|
||
if(s1[0]/s2[0] == s1[1]/s2[1] && s1[1]/s2[1]==s1[2]/s2[2]&& s1[2]/s2[2]==s1[0]/s2[0]) | ||
return 1; | ||
|
||
return 0; | ||
} | ||
|
||
int main() | ||
{ | ||
int s1[3],s2[3],a1[3],a2[3],i; | ||
cout<<"Side 1:"; | ||
for(i=0;i<3;i++){ | ||
cin>>s1[i]; | ||
} | ||
cout<<"Angle 1:"; | ||
for(i=0;i<3;i++){ | ||
cin>>a1[i]; | ||
} | ||
cout<<"Side 2:"; | ||
for(i=0;i<3;i++){ | ||
cin>>s2[i]; | ||
} | ||
cout<<"Angle 2:"; | ||
for(i=0;i<3;i++){ | ||
cin>>a2[i]; | ||
} | ||
int aaa=prop(a1,a2); | ||
int sss=sides(s1,s2); | ||
int sas=sideangle(s1,s2,a1,a2); | ||
if(aaa==1||sss==1||sas==1) | ||
{ | ||
cout<<"Triangles are similar by "; | ||
if(aaa==1) | ||
cout<<"AAA "; | ||
if(sss==1) | ||
cout<<"SSS "; | ||
if(sas==1) | ||
cout<<"SAS"; | ||
} | ||
else | ||
cout<<"Triangles are not similar"; | ||
return 0; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#include <iostream> | ||
using namespace std; | ||
|
||
int islucky(int nn){ | ||
int no[100],count=0,s=0,r=0,i; | ||
|
||
for(i=0;nn>0;i++){ | ||
no[i]=nn%10; | ||
|
||
nn=nn/10; | ||
count++; | ||
} | ||
|
||
|
||
for(i=0;i<count/2;i++){ | ||
s+=no[i]; | ||
} | ||
for(i=(count/2);i<count;i++){ | ||
r+=no[i]; | ||
} | ||
|
||
|
||
if(s==r){ | ||
return 1;} | ||
|
||
return 0; | ||
} | ||
|
||
|
||
int main() | ||
{ | ||
int n; | ||
cout<<"Enter the number n: "; | ||
cin>>n; | ||
|
||
int lucky=islucky(n); | ||
if(lucky==1) cout<<"Lucky"; | ||
else cout<<"unlucky"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#include <iostream> | ||
using namespace std; | ||
|
||
int main() | ||
{ | ||
int f[100],i,n; | ||
f[0]=0;f[1]=1; | ||
|
||
|
||
cout<<"Enter the position to find in fibonacci sequence: "; | ||
cin>>n; | ||
for(i=2;i<n;i++){ | ||
|
||
f[i]=f[i-1]+f[i-2]; | ||
} | ||
cout<<"The "<<n<<"th element is "<<f[n-1]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#include <iostream> | ||
using namespace std; | ||
|
||
void toh(int n,char a ,char c,char b){ | ||
if(n==1){ | ||
cout<<"Move disk 1 from "<<a<<" to "<<c<<"\n"; | ||
return ;} | ||
else | ||
toh(n-1,a,b,c); | ||
cout<<"Move disk "<<n<<" from "<<a<<" to "<<c<< "\n"; | ||
toh(n-1,b,c,a); | ||
|
||
} | ||
|
||
|
||
int main() | ||
{ | ||
int n;char a,b,c; | ||
cout<<"Enter the number of disks in tower 1: "; | ||
cin>>n; | ||
toh(n, 'A', 'C', 'B'); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#include <iostream> | ||
using namespace std; | ||
|
||
int gcd(int a,int b){ | ||
if(b==0) | ||
return a; | ||
return gcd(b,a%b); | ||
} | ||
|
||
int lcm(int arr[],int n) | ||
{ | ||
int result=arr[0]; | ||
for (int i=1;i<n;i++) | ||
result=(((arr[i]*result))/(gcd(arr[i],result))); | ||
|
||
return result; | ||
} | ||
int main() | ||
{ | ||
int i,n; | ||
cout<<"Enter the number of elements :"; | ||
cin>>n; | ||
int arr[n]; | ||
for(i=0;i<n;i++){ | ||
cin>>arr[i]; | ||
} | ||
int no=sizeof(arr)/sizeof(arr[0]); | ||
int s=lcm(arr,no); | ||
cout<<s; | ||
return 0; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#include <iostream> | ||
#include <algorithm> | ||
#include <cmath> | ||
using namespace std; | ||
|
||
bool approx_equal(double x, double y) | ||
{ | ||
const double e=1E-1; | ||
if (x == 0) return fabs(y)<=e; | ||
if (y == 0) return fabs(x)<=e; | ||
return fabs(x - y)/max(fabs(x),fabs(y))<=e; | ||
} | ||
|
||
int main() | ||
{ | ||
double x; | ||
cout << "Enter first number: "; | ||
cin >> x; | ||
|
||
double y; | ||
cout << "Enter second number: "; | ||
cin >> y; | ||
|
||
double th; | ||
cout<<"Enter tolerance level: "; | ||
cin>>th; | ||
|
||
|
||
if(approx_equal(x,y)){ | ||
if((fabs(x)-fabs(y))<th){ | ||
cout << "Less than tolerance level....The numbers are approximately equal.\n"; | ||
} | ||
|
||
else | ||
cout << "Greater than tolerance level.... The numbers are different.\n";} | ||
|
||
return 0; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from pattern.text.en import singularize,pluralize | ||
|
||
def SingularPlural(word,num): | ||
if type(num) is int: | ||
if num==1 or num==-1: | ||
w=singularize(word) | ||
else: | ||
w=pluralize(word) | ||
print(w) | ||
elif type(num) is str: | ||
if word==singularize(num): | ||
print("Singular: ",singularize(word)) | ||
print("Plural: ",pluralize(word)) | ||
elif num==singularize(word): | ||
print("Singular: ",singularize(num)) | ||
print("Plural: ",pluralize(num)) | ||
elif singularize(word)==singularize(num): | ||
print("Singular: ",word) | ||
print("Plural: ",pluralize(word)) | ||
else: | ||
print("Invalid Input") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from urllib.parse import urlparse | ||
|
||
def is_url(url): | ||
return bool(urlparse(url).netloc) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
def det(l): | ||
n=len(l) | ||
if (n>2): | ||
i=1 | ||
t=0 | ||
sum=0 | ||
while t<=n-1: | ||
d={} | ||
t1=1 | ||
while t1<=n-1: | ||
m=0 | ||
d[t1]=[] | ||
while m<=n-1: | ||
if (m==t): | ||
u=0 | ||
else: | ||
d[t1].append(l[t1][m]) | ||
m+=1 | ||
t1+=1 | ||
l1=[d[x] for x in d] | ||
sum=sum+i*(l[0][t])*(det(l1)) | ||
i=i*(-1) | ||
t+=1 | ||
return sum | ||
else: | ||
return (l[0][0]*l[1][1]-l[0][1]*l[1][0]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
def spiral(m,n,a) : | ||
k=0 | ||
l=0 | ||
|
||
while (k < m and l < n): | ||
for i in range(l,n): | ||
print(a[k][i],end = " ") | ||
k+=1 | ||
|
||
for i in range(k,m): | ||
print(a[i][n-1],end=" ") | ||
|
||
n -=1 | ||
|
||
if ( k < m) : | ||
for i in range(n-1,(l-1),-1) : | ||
print(a[m - 1][i],end=" ") | ||
|
||
m-=1 | ||
|
||
if(l<n): | ||
for i in range(m-1,k-1,-1): | ||
print(a[i][l],end=" ") | ||
|
||
l+=1 | ||
|
||
a=[[1,2,3],[4,5,6],[7,8,9]] | ||
|
||
r=3 | ||
c=3 | ||
spiral(r,c,a) |
Oops, something went wrong.