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

assign. by saurabh yadav #115

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
46 changes: 46 additions & 0 deletions saurabh yadav/11th may class answers/1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

#include <bits/stdc++.h>
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 "<<getSingle(arr, n);
return 0;
}


Binary file added saurabh yadav/11th may class answers/1.exe
Binary file not shown.
28 changes: 28 additions & 0 deletions saurabh yadav/11th may class answers/2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

#include <bits/stdc++.h>
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;
}

Binary file added saurabh yadav/11th may class answers/2.exe
Binary file not shown.
46 changes: 46 additions & 0 deletions saurabh yadav/11th may class answers/3.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

#include <bits/stdc++.h>
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;
}

Binary file added saurabh yadav/11th may class answers/3.exe
Binary file not shown.
23 changes: 23 additions & 0 deletions saurabh yadav/11th may class answers/4.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@


#include <iostream>
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;
}

Binary file added saurabh yadav/11th may class answers/4.exe
Binary file not shown.
28 changes: 28 additions & 0 deletions saurabh yadav/11th may class answers/5.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

#include<bits/stdc++.h>
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;
}

Binary file added saurabh yadav/11th may class answers/5.exe
Binary file not shown.
35 changes: 35 additions & 0 deletions saurabh yadav/12th may class answers/1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

#include<bits/stdc++.h>

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;
}


Binary file added saurabh yadav/12th may class answers/1.exe
Binary file not shown.
37 changes: 37 additions & 0 deletions saurabh yadav/12th may class answers/2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include<iostream>
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<n-1; i++)

if (arr[i] != arr[i+1])
temp[j++] = arr[i];

temp[j++] = arr[n-1];

for (int i=0; i<j; i++)
arr[i] = temp[i];

return j;
}

int main()
{
int arr[] = {1, 2, 2, 3, 4, 4, 4, 5, 5};
int n = sizeof(arr) / sizeof(arr[0]);

n = removeDuplicates(arr, n);

for (int i=0; i<n; i++)
cout << arr[i] << " ";

return 0;
}

Binary file added saurabh yadav/12th may class answers/2.exe
Binary file not shown.
27 changes: 27 additions & 0 deletions saurabh yadav/12th may class answers/3.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

#include <iostream>
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;
}

Binary file added saurabh yadav/12th may class answers/3.exe
Binary file not shown.
27 changes: 27 additions & 0 deletions saurabh yadav/12th may class answers/4.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <stdio.h>
#include <string.h>

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;
}

Binary file added saurabh yadav/12th may class answers/4.exe
Binary file not shown.
18 changes: 18 additions & 0 deletions saurabh yadav/12th may class answers/5.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

#include <stdio.h>
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;
}
Binary file added saurabh yadav/12th may class answers/5.exe
Binary file not shown.
43 changes: 43 additions & 0 deletions saurabh yadav/13th may class answers/1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include<stdio.h>

#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;i<r;i++)

for(j=0;j<c;j++)

scanf("%d",&a[i][j]);

for(i=0;i<r;i++)

{

max[i]=a[i][j];

for(j=0;j<c;j++)

if(a[i][j]>max[i])

max[i]=a[i][j];

}

for(i=0;i<r;i++)

printf("\nMaximum element from %d row is:%d",i,max[i]);

}
Binary file added saurabh yadav/13th may class answers/1.exe
Binary file not shown.
Loading