Skip to content

Commit 3e763a5

Browse files
authored
11 may (assigment 1(shivraj singh(jiet_cstt_batch_3))
1 parent 7ad1b82 commit 3e763a5

File tree

10 files changed

+168
-0
lines changed

10 files changed

+168
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
int findSingle(int ar[], int ar_size)
5+
{
6+
int res = ar[0];
7+
for (int i = 1; i < ar_size; i++)
8+
res = res ^ ar[i];
9+
10+
return res;
11+
}
12+
13+
int main()
14+
{
15+
int ar[] = {2, 3, 5, 4, 5, 3, 4};
16+
int n = sizeof(ar) / sizeof(ar[0]);
17+
cout << "element occuring once is "
18+
<< findSingle(ar , n);
19+
return 0;
20+
}
21+
22+
// output is : element occuring once is 2
1.83 MB
Binary file not shown.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
int numberOfPaths(int m, int n)
5+
{
6+
if (m == 1 || n == 1)
7+
return 1;
8+
9+
return numberOfPaths(m - 1, n) + numberOfPaths(m, n - 1);
10+
}
11+
12+
int main()
13+
{
14+
cout << numberOfPaths(3, 3);
15+
return 0;
16+
}
17+
18+
// output is 6
19+
1.83 MB
Binary file not shown.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
int solve(int low, int high, int T)
5+
{
6+
while (low <= high)
7+
{
8+
int mid = (low + high) / 2;
9+
10+
if ((mid * (mid + 1)) == T)
11+
return mid;
12+
13+
if (mid > 0 && (mid * (mid + 1)) > T &&
14+
(mid * (mid - 1)) <= T)
15+
return mid - 1;
16+
17+
if ((mid * (mid + 1)) > T)
18+
high = mid - 1;
19+
20+
else
21+
low = mid + 1;
22+
}
23+
return -1;
24+
}
25+
26+
int main()
27+
{
28+
int T = 15;
29+
30+
int ans = solve(1, T, 2 * T);
31+
32+
if (ans != -1)
33+
ans--;
34+
35+
cout << "Number of stair steps = "
36+
<< ans << endl;
37+
return 0;
38+
}
39+
40+
// output is Number of stair steps = 4
1.83 MB
Binary file not shown.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
double Square(double n, double i, double j)
5+
{
6+
double mid = (i + j) / 2;
7+
double mul = mid * mid;
8+
9+
10+
if ((mul == n) || (abs(mul - n) < 0.00001))
11+
return mid;
12+
13+
else if (mul < n)
14+
return Square(n, mid, j);
15+
16+
else
17+
return Square(n, i, mid);
18+
}
19+
20+
void findSqrt(double n)
21+
{
22+
double i = 1;
23+
24+
bool found = false;
25+
while (!found) {
26+
27+
if (i * i == n) {
28+
cout << fixed << setprecision(0) << i;
29+
found = true;
30+
}
31+
else if (i * i > n) {
32+
33+
double res = Square(n, i - 1, i);
34+
cout << fixed << setprecision(5) << res;
35+
found = true;
36+
}
37+
i++;
38+
}
39+
}
40+
41+
int main()
42+
{
43+
double n = 7;
44+
45+
findSqrt(n);
46+
47+
return 0;
48+
}
49+
//output is 2.4575
1.84 MB
Binary file not shown.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#include <stdio.h>
2+
3+
int PathCounting(int m, int n)
4+
{
5+
int ctr[m][n];
6+
for (int i = 0; i < m; i++)
7+
{
8+
ctr[i][0] = 1;
9+
}
10+
for (int j = 0; j < n; j++)
11+
{
12+
ctr[0][j] = 1;
13+
}
14+
for (int i = 1; i < m; i++)
15+
{
16+
for (int j = 1; j < n; j++)
17+
{
18+
ctr[i][j] = ctr[i-1][j] + ctr[i][j-1];
19+
}
20+
}
21+
return ctr[m-1][n-1];
22+
}
23+
24+
int main()
25+
{
26+
int p,q;
27+
printf("enter no. of rows of matrix ");
28+
scanf("%d",&p);
29+
printf("enter no. of column of matrix ");
30+
scanf("%d",&q);
31+
printf("The size of matrix is : %d, %d\n",p,q);
32+
printf("The all possible paths from top left to bottom right is: %d \n",PathCounting(p,q));
33+
}
34+
// output is
35+
// enter no. of rows of matrix 3
36+
// enter no. of column of matrix 4
37+
// The size of matrix is : 3, 4
38+
// The all possible paths from top left to bottom right is: 10
130 KB
Binary file not shown.

0 commit comments

Comments
 (0)