diff --git a/saurabh yadav/11th may class answers/1.cpp b/saurabh yadav/11th may class answers/1.cpp new file mode 100644 index 0000000..7ac0b17 --- /dev/null +++ b/saurabh yadav/11th may class answers/1.cpp @@ -0,0 +1,46 @@ + +#include +using namespace std; + +int getSingle(int arr[], int n) +{ + int ones = 0, twos = 0 ; + + int common_bit_mask; + + + for( int i=0; i< n; i++ ) + { + twos = twos | (ones & arr[i]); + + + + ones = ones ^ arr[i]; + + + + common_bit_mask = ~(ones & twos); + + + ones &= common_bit_mask; + + + + twos &= common_bit_mask; + + + } + + return ones; +} + + +int main() +{ + int arr[] = {3, 3, 2, 3}; + int n = sizeof(arr) / sizeof(arr[0]); + cout<<"The element with single occurrence is "< +using namespace std; + + +int minXOR(int arr[], int n) +{ + int min_xor = INT_MAX; + + + for (int i = 0; i < n; i++) + for (int j = i + 1; j < n; j++) + + + min_xor = min(min_xor, arr[i] ^ arr[j]); + + return min_xor; +} + + +int main() +{ + int arr[] = { 9, 5, 3 }; + int n = sizeof(arr) / sizeof(arr[0]); + cout << minXOR(arr, n) << endl; + return 0; +} + diff --git a/saurabh yadav/11th may class answers/2.exe b/saurabh yadav/11th may class answers/2.exe new file mode 100644 index 0000000..eba266f Binary files /dev/null and b/saurabh yadav/11th may class answers/2.exe differ diff --git a/saurabh yadav/11th may class answers/3.cpp b/saurabh yadav/11th may class answers/3.cpp new file mode 100644 index 0000000..f6609a8 --- /dev/null +++ b/saurabh yadav/11th may class answers/3.cpp @@ -0,0 +1,46 @@ + +#include +using namespace std; + + +int solve(int low, int high, int T) +{ + while (low <= high) { + int mid = (low + high) / 2; + + + if ((mid * (mid + 1)) == T) + return mid; + + + if (mid > 0 && (mid * (mid + 1)) > T && + (mid * (mid - 1)) <= T) + return mid - 1; + + + if ((mid * (mid + 1)) > T) + high = mid - 1; + + + else + low = mid + 1; + } + return -1; +} + +int main() +{ + int T = 15; + + + int ans = solve(1, T, 2 * T); + + + if (ans != -1) + ans--; + + cout << "Number of stair steps = " + << ans << endl; + return 0; +} + diff --git a/saurabh yadav/11th may class answers/3.exe b/saurabh yadav/11th may class answers/3.exe new file mode 100644 index 0000000..d2df6d8 Binary files /dev/null and b/saurabh yadav/11th may class answers/3.exe differ diff --git a/saurabh yadav/11th may class answers/4.cpp b/saurabh yadav/11th may class answers/4.cpp new file mode 100644 index 0000000..e984e02 --- /dev/null +++ b/saurabh yadav/11th may class answers/4.cpp @@ -0,0 +1,23 @@ + + +#include +using namespace std; + + +int numberOfPaths(int m, int n) +{ + + if (m == 1 || n == 1) + return 1; + + + return numberOfPaths(m - 1, n) + numberOfPaths(m, n - 1); + +} + +int main() +{ + cout << numberOfPaths(3, 3); + return 0; +} + diff --git a/saurabh yadav/11th may class answers/4.exe b/saurabh yadav/11th may class answers/4.exe new file mode 100644 index 0000000..8c460da Binary files /dev/null and b/saurabh yadav/11th may class answers/4.exe differ diff --git a/saurabh yadav/11th may class answers/5.cpp b/saurabh yadav/11th may class answers/5.cpp new file mode 100644 index 0000000..a482f1e --- /dev/null +++ b/saurabh yadav/11th may class answers/5.cpp @@ -0,0 +1,28 @@ + +#include +using namespace std; + + +int floorSqrt(int x) +{ + + if (x == 0 || x == 1) + return x; + + + int i = 1, result = 1; + while (result <= x) + { + i++; + result = i * i; + } + return i - 1; +} + +int main() +{ + int x = 11; + cout << floorSqrt(x) << endl; + return 0; +} + diff --git a/saurabh yadav/11th may class answers/5.exe b/saurabh yadav/11th may class answers/5.exe new file mode 100644 index 0000000..d7c6b21 Binary files /dev/null and b/saurabh yadav/11th may class answers/5.exe differ diff --git a/saurabh yadav/12th may class answers/1.cpp b/saurabh yadav/12th may class answers/1.cpp new file mode 100644 index 0000000..005ebf1 --- /dev/null +++ b/saurabh yadav/12th may class answers/1.cpp @@ -0,0 +1,35 @@ + +#include + +using namespace std; + +int recSearch(int arr[], int l, + int r, int x) +{ + if (r < l) + return -1; + if (arr[l] == x) + return l; + if (arr[r] == x) + return r; + return recSearch(arr, l + 1, + r - 1, x); +} + +int main() +{ + int arr[] = {12, 34, 54, 2, 3}, i; + int n = sizeof(arr) / sizeof(arr[0]); + int x = 3; + int index = recSearch(arr, 0, n - 1, x); + if (index != -1) + cout << "Element " << x + << " is present at index " + << index; + else + cout << "Element" << x + << " is not present" ; + return 0; +} + + diff --git a/saurabh yadav/12th may class answers/1.exe b/saurabh yadav/12th may class answers/1.exe new file mode 100644 index 0000000..43d2c9f Binary files /dev/null and b/saurabh yadav/12th may class answers/1.exe differ diff --git a/saurabh yadav/12th may class answers/2.cpp b/saurabh yadav/12th may class answers/2.cpp new file mode 100644 index 0000000..27181ad --- /dev/null +++ b/saurabh yadav/12th may class answers/2.cpp @@ -0,0 +1,37 @@ +#include +using namespace std; + +int removeDuplicates(int arr[], int n) +{ + if (n==0 || n==1) + return n; + + int temp[n]; + + int j = 0; + for (int i=0; i +using namespace std; + +void decToBinary(int n) +{ + int binaryNum[32]; + + int i = 0; + while (n > 0) { + + binaryNum[i] = n % 2; + n = n / 2; + i++; + } + + for (int j = i - 1; j >= 0; j--) + cout << binaryNum[j]; +} + +int main() +{ + int n = 17; + decToBinary(n); + return 0; +} + diff --git a/saurabh yadav/12th may class answers/3.exe b/saurabh yadav/12th may class answers/3.exe new file mode 100644 index 0000000..bd55f16 Binary files /dev/null and b/saurabh yadav/12th may class answers/3.exe differ diff --git a/saurabh yadav/12th may class answers/4.cpp b/saurabh yadav/12th may class answers/4.cpp new file mode 100644 index 0000000..4da36fb --- /dev/null +++ b/saurabh yadav/12th may class answers/4.cpp @@ -0,0 +1,27 @@ +#include +#include + +void isPalindrome(char str[]) +{ + int l = 0; + int h = strlen(str) - 1; + + while (h > l) + { + if (str[l++] != str[h--]) + { + printf("%s is Not Palindrome", str); + return; + } + } + printf("%s is palindrome", str); +} + +int main() +{ + isPalindrome("yadav"); + isPalindrome("\nji"); + isPalindrome("\nrocks"); + return 0; +} + diff --git a/saurabh yadav/12th may class answers/4.exe b/saurabh yadav/12th may class answers/4.exe new file mode 100644 index 0000000..8fbbe9f Binary files /dev/null and b/saurabh yadav/12th may class answers/4.exe differ diff --git a/saurabh yadav/12th may class answers/5.cpp b/saurabh yadav/12th may class answers/5.cpp new file mode 100644 index 0000000..a9b0400 --- /dev/null +++ b/saurabh yadav/12th may class answers/5.cpp @@ -0,0 +1,18 @@ + +#include +int main() +{ + char s1[] = "nahi aata tha fork vgerh to late ho gaya uploding... consider kr lena isse bhi!!", s2[100], i; + + printf("string s1 : %s\n", s1); + + for (i = 0; s1[i] != '\0'; ++i) { + s2[i] = s1[i]; + } + + s2[i] = '\0'; + + printf("String s2 : %s", s2); + + return 0; +} diff --git a/saurabh yadav/12th may class answers/5.exe b/saurabh yadav/12th may class answers/5.exe new file mode 100644 index 0000000..916ba14 Binary files /dev/null and b/saurabh yadav/12th may class answers/5.exe differ diff --git a/saurabh yadav/13th may class answers/1.c b/saurabh yadav/13th may class answers/1.c new file mode 100644 index 0000000..337f9b6 --- /dev/null +++ b/saurabh yadav/13th may class answers/1.c @@ -0,0 +1,43 @@ +#include + +#define m 20 + +main(){ + +int a[m][m],i,j=0,r,max[10],c; + +printf("Enter the number of rows"); + +scanf("%d",&r); + +printf("Enter the number of column"); + +scanf("%d",&c); + +printf("Enter the elements"); + +for(i=0;imax[i]) + +max[i]=a[i][j]; + +} + +for(i=0;i + +int main() +{ + int m, n, p, q, c, d, k, sum = 0; + int first[10][10], second[10][10], multiply[10][10]; + + printf("Enter the number of rows and columns of first matrix\n"); + scanf("%d%d", &m, &n); + printf("Enter the elements of first matrix\n"); + + for ( c = 0 ; c < m ; c++ ) + for ( d = 0 ; d < n ; d++ ) + scanf("%d", &first[c][d]); + + printf("Enter the number of rows and columns of second matrix\n"); + scanf("%d%d", &p, &q); + + if ( n != p ) + printf("Matrices with entered orders can't be multiplied with each other.\n"); + else + { + printf("Enter the elements of second matrix\n"); + + for ( c = 0 ; c < p ; c++ ) + for ( d = 0 ; d < q ; d++ ) + scanf("%d", &second[c][d]); + + for ( c = 0 ; c < m ; c++ ) + { + for ( d = 0 ; d < q ; d++ ) + { + for ( k = 0 ; k < p ; k++ ) + { + sum = sum + first[c][k]*second[k][d]; + } + + multiply[c][d] = sum; + sum = 0; + } + } + + printf("Product of entered matrices:-\n"); + + for ( c = 0 ; c < m ; c++ ) + { + for ( d = 0 ; d < q ; d++ ) + printf("%d\t", multiply[c][d]); + + printf("\n"); + } + } + + return 0; +} diff --git a/saurabh yadav/13th may class answers/2.exe b/saurabh yadav/13th may class answers/2.exe new file mode 100644 index 0000000..4bbee51 Binary files /dev/null and b/saurabh yadav/13th may class answers/2.exe differ diff --git a/saurabh yadav/13th may class answers/3.c b/saurabh yadav/13th may class answers/3.c new file mode 100644 index 0000000..68afd88 --- /dev/null +++ b/saurabh yadav/13th may class answers/3.c @@ -0,0 +1,24 @@ +#include +int main() { + int a, b, x, y, t, gcd, lcm; + + printf("Enter two integers\n"); + scanf("%d%d", &x, &y); + + a = x; + b = y; + + while (b != 0) { + t = b; + b = a % b; + a = t; + } + + gcd = a; + lcm = (x*y)/gcd; + + printf("Greatest common divisor of %d and %d = %d\n", x, y, gcd); + printf("Least common multiple of %d and %d = %d\n", x, y, lcm); + + return 0; +} diff --git a/saurabh yadav/13th may class answers/3.exe b/saurabh yadav/13th may class answers/3.exe new file mode 100644 index 0000000..bdc7811 Binary files /dev/null and b/saurabh yadav/13th may class answers/3.exe differ diff --git a/saurabh yadav/13th may class answers/4.c b/saurabh yadav/13th may class answers/4.c new file mode 100644 index 0000000..3abc1a0 --- /dev/null +++ b/saurabh yadav/13th may class answers/4.c @@ -0,0 +1,16 @@ +#include +int main() { + int n, rev = 0, remainder; + printf("Enter an integer: "); + scanf("%d", &n); + while (n != 0) { + remainder = n % 10; + rev = rev * 10 + remainder; + n /= 10; + } + + + printf("\nReversed number = %d", rev); + + +} diff --git a/saurabh yadav/13th may class answers/4.exe b/saurabh yadav/13th may class answers/4.exe new file mode 100644 index 0000000..57f1ed2 Binary files /dev/null and b/saurabh yadav/13th may class answers/4.exe differ diff --git a/saurabh yadav/13th may class answers/5.c b/saurabh yadav/13th may class answers/5.c new file mode 100644 index 0000000..b3f503e --- /dev/null +++ b/saurabh yadav/13th may class answers/5.c @@ -0,0 +1,39 @@ + + + #include + void main() + { + + int i, j, a, n, number[30]; + printf("Enter the value of N \n"); + scanf("%d", &n); + + printf("Enter the numbers \n"); + for (i = 0; i < n; ++i) + scanf("%d", &number[i]); + + for (i = 0; i < n; ++i) + { + + for (j = i + 1; j < n; ++j) + { + + if (number[i] > number[j]) + { + + a = number[i]; + number[i] = number[j]; + number[j] = a; + + } + + } + + } + + printf("The numbers arranged in ascending order are given below \n"); + for (i = 0; i < n; ++i) + printf("%d\n", number[i]); + + } + diff --git a/saurabh yadav/13th may class answers/5.exe b/saurabh yadav/13th may class answers/5.exe new file mode 100644 index 0000000..f7acc27 Binary files /dev/null and b/saurabh yadav/13th may class answers/5.exe differ