Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 302 of 377

Check for possible path in 2D matrix in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 694 Views

Consider we have a 2D array. We have to find if we can get a path from topleft corner to bottom-right corner. The matrix is filled with 0s and 1s. 0 indicates open area, 1 indicates blockage. Note that the top-left corner will always be 1.Suppose a matrix is like below −0001010011000101000000100One path is marked as green, there are some other paths also. So the program will return true, if there is a path, otherwise false.We will solve this problem, by changing all accessible node to -1, First change the value of starting point to -1, then get next value ...

Read More

Check given matrix is magic square or not in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 2K+ Views

Here we will see, if a matrix is magic square or not, a magic square is a square matrix, where the sum of each row, each column, and each diagonal are same.Suppose a matrix is like below −618753294This is a magic square, if we see, the sum of each row, column and diagonals are 15.To check whether a matrix is magic square or not, we have to find the major diagonal sum and the secondary diagonal sum, if they are same, then that is magic square, otherwise not.Example#include #define N 3 using namespace std; bool isMagicSquare(int mat[][N]) {   ...

Read More

Bisymmetric matrix in C++?

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 255 Views

Here we will see one program that will help to check whether a matrix is bisymmetric or not. The Bisymmetric matrix is one square matrix that are symmetric about both of the major diagonals. The below matrix is an example of bisymmetric matrix.1 2 3 4 5 2 6 7 8 4 3 7 9 7 3 4 8 7 6 2 5 4 3 2 1AlgorithmcheckBiSymmetric(mat, n)Begin    for i in range 0 to n – 1, do       for j in range 0 to i – 1, do          if mat[i, j] is ...

Read More

Check if a number is in given base or not in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 332 Views

Suppose, we have a number string, we have to find that the number is of given base B or not? If the string is “101110”, b = 2, then the program will return true. If the string is “A8F”, base is 16, it will be true.The approach is very simple. If all of the character is in the range of symbols of the given base, then return true, otherwise false.Example#include using namespace std; bool inGivenBase(string s, int base) {    if (base > 16) //program can handle upto base 1       return false;       else ...

Read More

Check if a number is jumbled or not in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 560 Views

Here we will see one interesting problem to check whether a number is jumbled or not. A number is said to be jumbled if, for every digit, it's neighbor digit differs by max 1. For example, a number 1223 is jumbled, but 1256 is not jumbled.To solve this problem, we have to check if a digit has a neighbor with a difference greater than 1. If such digit is found, then return false, otherwise true.Example#include #include using namespace std; bool isJumbled(int number) {    if (number / 10 == 0) //for single digit number is is always jumbled ...

Read More

Check if a number is perfect square without finding square root in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 2K+ Views

Suppose a number is given, we have to check whether the number is a perfect square or not. We will not use the square root operation to check it. Suppose a number 1024 is there, this is a perfect square, but 1000 is not a perfect square. The logic is simple, we have to follow this algorithm to get the result.AlgorithmisPerfectSquare(n) −input − The number noutput − true, if the number is a perfect square, otherwise, falsebegin    for i := 1, i2 ≤ n, increase i by 1:       if n is divisible by i, and n ...

Read More

Check if a number is power of 8 or not in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 552 Views

In this section, we will see, if a number is the power of 8 or not using some easier method. If a number like 4096 is there, then the program will return true, as this is the power of 8.The trick is simple. we will calculate log8(num). If this is an integer, then n is the power of 8. Here we will use the tranc(n) function to find the closest integer of the double value.Example#include #include using namespace std; bool isPowerOfEight(int n) {    double val = log(n)/log(8); //get log n to the base 8    return (val ...

Read More

Check if a number is power of k using base changing methods in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 271 Views

Here we will see a program, if one number is given, another value k is also given, we have to check whether the number is power of k or not. But we have to perform the base changing method to solve this problem. Suppose a number is 27, and k = 3. Then by base changing method, the 27 will be 10003. Here after changing the base if there is only one occurrence of digit 1, and others are 0, then the number is power of k.To solve this problem, we will follow these steps.Steps −define flag := falsewhile number > ...

Read More

Check if a point is inside, outside or on the ellipse in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 857 Views

Suppose, one ellipse is given (the center coordinate (h, k) and semi-major axis a, and semi-minor axis b), another point is also given. We have to find whether the point is inside the ellipse or not. To solve it, we have to solve the following equation for the given point (x, y).$$\frac{\left(x-h\right)^2}{a^2}+\frac{\left(y-k\right)^2}{b^2}\leq1$$If the result is less than one, then the point is inside the ellipse, otherwise not.Example#include #include using namespace std; bool isInsideEllipse(int h, int k, int x, int y, int a, int b) {    int res = (pow((x - h), 2) / pow(a, 2)) + (pow((y ...

Read More

Check if a point is inside, outside or on the parabola in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 439 Views

Suppose, one parabola is given (the vertex coordinate (h, k) and distance from focus and vertex is a), another point is also given. We have to find whether the point is inside the parabola or not. To solve it, we have to solve the following equation for the given point (x, y)\left(y-k\right)^2=4a\left(x-h\right)If the result is less than 0, then this is present inside the parabola if it is 0, then it is on the parabola, and if greater than 0, then outside of the parabola.Example#include #include using namespace std; int isInsideParabola(int h, int k, int x, int y, ...

Read More
Showing 3011–3020 of 3,768 articles
« Prev 1 300 301 302 303 304 377 Next »
Advertisements