Skip to content

Commit 852e7ed

Browse files
author
Bhrigu Kansra
authored
Merge pull request #157 from seemantaggarwal/master
added in math and algorithms
2 parents 9bee4dc + 60a5af2 commit 852e7ed

File tree

7 files changed

+154
-0
lines changed

7 files changed

+154
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
2+
3+
#define N 4
4+
#include<stdio.h>
5+
#include<stdbool.h>
6+
7+
void printSolution(int board[N][N])
8+
{
9+
for (int i = 0; i < N; i++)
10+
{
11+
for (int j = 0; j < N; j++)
12+
printf(" %d ", board[i][j]);
13+
printf("\n");
14+
}
15+
}
16+
17+
18+
bool isSafe(int board[N][N], int row, int col)
19+
{
20+
int i, j;
21+
22+
/* Check this row on left side */
23+
for (i = 0; i < col; i++)
24+
if (board[row][i])
25+
return false;
26+
27+
/* Check upper diagonal on left side */
28+
for (i=row, j=col; i>=0 && j>=0; i--, j--)
29+
if (board[i][j])
30+
return false;
31+
32+
/* Check lower diagonal on left side */
33+
for (i=row, j=col; j>=0 && i<N; i++, j--)
34+
if (board[i][j])
35+
return false;
36+
37+
return true;
38+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
3+
#include<bits/stdc++.h>
4+
using namespace std;
5+
6+
void printFun(int test)
7+
{
8+
if (test < 1)
9+
return;
10+
else
11+
{
12+
cout << test << " ";
13+
printFun(test-1); // statement 2
14+
cout << test << " ";
15+
return;
16+
}
17+
}
18+
19+
int main()
20+
{
21+
int test = 3;
22+
printFun(test);
23+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
3+
4+
def printFun(test):
5+
6+
if (test < 1):
7+
return
8+
else:
9+
10+
print( test,end = " ")
11+
printFun(test-1) # statement 2
12+
print( test,end = " ")
13+
return
14+
15+
16+
test = 3
17+
printFun(test)

contributors.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,4 @@
4242
40. [Riya Singh](https://github.com/riya24899)
4343
41. [Sarthak gupta](https://github.com/sarthak-g)
4444
42. [Your Name](https://github.com/yourusername)
45+
43. [Seemant Aggarwal] (https://github.com/seemantaggarwal)

math/C++/determinant.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#define N 4
2+
#include <bits/stdc++.h>
3+
using namespace std;
4+
5+
6+
void getCofactor(int mat[N][N], int temp[N][N], int p, int q, int n)
7+
{
8+
int i = 0, j = 0;
9+
10+
11+
for (int row = 0; row < n; row++)
12+
{
13+
for (int col = 0; col < n; col++)
14+
{
15+
16+
if (row != p && col != q)
17+
{
18+
temp[i][j++] = mat[row][col];
19+
20+
21+
if (j == n - 1)
22+
{
23+
j = 0;
24+
i++;
25+
}
26+
}
27+
}
28+
}
29+
}

math/C++/prime number.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
int main()
5+
{
6+
int n, i;
7+
bool isPrime = true;
8+
9+
cout << "Enter a positive integer: ";
10+
cin >> n;
11+
12+
for(i = 2; i <= n / 2; ++i)
13+
{
14+
if(n % i == 0)
15+
{
16+
isPrime = false;
17+
break;
18+
}
19+
}
20+
if (isPrime)
21+
cout << "This is a prime number";
22+
else
23+
cout << "This is not a prime number";
24+
25+
return 0;
26+
}

math/Python/prime number.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
num = 407
2+
3+
# take input from the user
4+
# num = int(input("Enter a number: "))
5+
6+
# prime numbers are greater than 1
7+
if num > 1:
8+
# check for factors
9+
for i in range(2,num):
10+
if (num % i) == 0:
11+
print(num,"is not a prime number")
12+
print(i,"times",num//i,"is",num)
13+
break
14+
else:
15+
print(num,"is a prime number")
16+
17+
# if input number is less than
18+
# or equal to 1, it is not prime
19+
else:
20+
print(num,"is not a prime number")

0 commit comments

Comments
 (0)