diff --git a/first_and_last_occurenece_of_Element_of_String.cpp b/first_and_last_occurenece_of_Element_of_String.cpp new file mode 100644 index 0000000..eb6c9ae --- /dev/null +++ b/first_and_last_occurenece_of_Element_of_String.cpp @@ -0,0 +1,28 @@ +#include +using namespace std; +void occurence(string str, int idx,char element){ + int first,last=-1; + if(idx == str.length()){ + cout<>str; +char element; +cin>>element; +occurence(str,0,element); +} diff --git a/middle_of_three_numbers.cpp b/middle_of_three_numbers.cpp new file mode 100644 index 0000000..2e027d7 --- /dev/null +++ b/middle_of_three_numbers.cpp @@ -0,0 +1,25 @@ +#include +using namespace std; +int main(){ +int A,B,C; +cin>>A>>B>>C; +//if((A-B)*(A-C)<0) return A; +//else if((B-A)*(B-C)<0) return B; +//else return C; +//time taken 5 seconds +//if(A>B) swap(A,B); +//if(B>C)swap(B,C); +//if(A>B) swap(A,B); +//return B; +//4 seconds + +//if(A>B && B>C || C>B && B>A) +//return B; +//else if(B>A && A>C || A>B && C>B) +//return A; +//else if(A>B && C>B || B>A && B>C) +//return C; +//worst method 9 seconds + +return (A>B && B>C)||(C>B && B>A) ? B : (B>A && A>C)||(C>A && A>B) ? A : C; +}