Skip to content

Commit 229ea9e

Browse files
authored
Add files via upload
1 parent 2d22700 commit 229ea9e

2 files changed

Lines changed: 49 additions & 0 deletions

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package InfinityJune21.BasicMaths.Combinations;
2+
3+
public class PairWithGivenSum {
4+
public static void main(String[] args) {
5+
int arr[] = {1, 5, 7, -1};
6+
int size = arr.length;
7+
int count = 0;
8+
int sum = 6;
9+
10+
for(int i = 0; i < size; i++) {
11+
for(int j = (i + 1); j < size; j++) {
12+
int s = arr[i] + arr[j];
13+
14+
if(s == sum) {
15+
count++;
16+
}
17+
}
18+
}
19+
20+
System.out.println("Count: " + count);
21+
}
22+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package InfinityJune21.BasicMaths;
2+
3+
public class SumToNUsingNaturalNumbersUptoKWithRepetitions {
4+
static int numberOfWays(int N, int K) {
5+
int waysCount[] = new int[N + 1];
6+
7+
waysCount[0] = 1;
8+
9+
//Iterate from 1 to K
10+
for(int i = 1; i <= K; i++) {
11+
//Iterate from 1 to N
12+
for(int j = 1; j <= N; j++) {
13+
if(j >= i) {
14+
waysCount[j] = waysCount[j] + waysCount[j - i];
15+
}
16+
}
17+
}
18+
19+
return waysCount[N];
20+
}
21+
public static void main(String[] args) {
22+
int N = 8, K = 2;
23+
int count = numberOfWays(N, K);
24+
25+
System.out.println("Count: " + count);
26+
}
27+
}

0 commit comments

Comments
 (0)