Articles on Trending Technologies

Technical articles with clear explanations and examples

BFS using vectors & queue as per the algorithm of CLRS in C Program?

Arnab Chakraborty
Arnab Chakraborty
Updated on 20-Aug-2019 414 Views

In CLRS book the BFS algorithm is described using vectors and queue. We have to implement that algorithm using C++ STL. Let us see the algorithm at first.AlgorithmBFS(G, s) −begin    for each vertex u in G.V - {s}, do       u.color := white       u.d := infinity       u.p := NIL    done    s.color := green    s.d := 0    s.p := NIL    Q := NULL    insert s into Q    while Q is not null, do       u = delete from Q       for ...

Read More

Betrothed numbers in C Program?

Arnab Chakraborty
Arnab Chakraborty
Updated on 20-Aug-2019 630 Views

Here we will see the Betrothed number. This is a pair of numbers, such that the sum of the proper divisors of one number is one more than the other number. We have to find these pairsFor an example, the pair is like (48, 75). So the divisors of 48 is {1, 2, 3, 4, 6, 8, 12, 16, 24} and sum is 76. Similarly, the divisors of 75 is {1, 3, 5, 15, 25} so sum is 49.AlgorithmBetrothedPairs (n) −begin    for num in range 1 to n, do       sum := 1       for ...

Read More

Auxiliary Space with Recursive Functions in C Program?

Arnab Chakraborty
Arnab Chakraborty
Updated on 20-Aug-2019 446 Views

Here we will see how the auxiliary space is required for recursive function call. And how it is differing from the normal function call?Suppose we have one function like below −long fact(int n){    if(n == 0 || n == 1)       return 1;    return n * fact(n-1); }This function is recursive function. When we call it like fact(5), then it will store addresses inside the stack like below −fact(5) ---> fact(4) ---> fact(3) ---> fact(2) ---> fact(1)As the recursive functions are calling itself again and again, addresses are added into stack. So if the function is ...

Read More

Area of the biggest possible rhombus that can be inscribed in a rectangle in C Program?

Arnab Chakraborty
Arnab Chakraborty
Updated on 20-Aug-2019 171 Views

Here we will see one problem, where one rectangle is given. We have to find the area of largest rhombus that can be inscribed in the rectangle. The diagram will be look like below −The length of the rectangle is ‘l’ and breadth is ‘b’ So the area of the rhombus is −Source Code#include #include using namespace std; float area(float l, float b) {    if (l < 0 || b < 0) //if the values are negative it is invalid       return -1;    float area = (l*b) /2;    return area; } int main() {    float l = 20.0, b = 7;    cout

Read More

Area of squares formed by joining mid points repeatedly in C Program?

Arnab Chakraborty
Arnab Chakraborty
Updated on 20-Aug-2019 152 Views

Suppose we have one square whose side is ‘a’. We will make more squares by attaching the mid-points of the squares repeatedly. The number of repetition is n times. We have to find the area of nth square.As the side of the outer square is ‘a’, then area isNow using Pythagorean theorem, we can get the area of the second rectangle is −Similarly, area of 3rd square is −Using this we can understand that the area of nth square is −Example#include #include using namespace std; float area(float a, float n) {    if (a < 0 ) //if ...

Read More

Area of largest triangle that can be inscribed within a rectangle in C Program?

Arnab Chakraborty
Arnab Chakraborty
Updated on 20-Aug-2019 193 Views

Suppose one rectangle is given. We know the length L and breadth B of it. We have to find the area of largest triangle that can be inscribed within that rectangle −The largest triangle will always be the half of the rectangle. So it will beExample#include #include using namespace std; float area(float l, float b) {    if (l < 0 || b < 0 ) //if the valuse are negative it is invalid       return -1;    float area = (l*b)/2;    return area; } int main() {    float a = 10, b = 8;    cout

Read More

Area of Largest rectangle that can be inscribed in an Ellipse?

Arnab Chakraborty
Arnab Chakraborty
Updated on 20-Aug-2019 369 Views

Here we will see the area of largest rectangle that can be inscribed in an ellipse. The rectangle in ellipse will be like below −The a and b are the half of major and minor axis of the ellipse. The upper right corner of the rectangle is (x, y). So the area isNow, after making this equation as f(x) and maximizing the area, we will get the area asExample#include #include using namespace std; float area(float a, float b) {    if (a < 0 || b < 0 ) //if the valuse are negative it is invalid   ...

Read More

C Program for area of hexagon with given diagonal length?

Arnab Chakraborty
Arnab Chakraborty
Updated on 20-Aug-2019 439 Views

Here we will see how to get the area of one hexagon using diagonal length. The diagonal length of the hexagon is d.The interior angles of a regular hexagon are 120° each. The sum of all interior angles are 720°. If the diagonal is d, then area is −Example#include #include using namespace std; float area(float d) {    if (d < 0) //if d is negative it is invalid       return -1;    float area = (3 * sqrt(3) * d*d)/8.0;    return area; } int main() {    float r = 10;    cout

Read More

C Program for area of decagon inscribed within the circle?

Arnab Chakraborty
Arnab Chakraborty
Updated on 20-Aug-2019 244 Views

Here we will see how to get the area of decagon which is present inside the circle. The radius is given. The side of the decagon is ‘a’.As we know that the side of the decagon is like below −So the area is −Example#include #include using namespace std; float area(float r) {    if (r < 0) //if r is negative it is invalid       return -1;    float area = (5 * pow(r, 2) * (3 - sqrt(5)) * (sqrt(5) + (2 * sqrt(5)))) / 4;    return area; } int main() {    float r = 8;    cout

Read More

Area of circle inscribed within rhombus in C Program?

Arnab Chakraborty
Arnab Chakraborty
Updated on 20-Aug-2019 222 Views

Here we will see the area of circle which is inscribed in a rhombus. The diagonals of the rhombus are ‘a’ and ‘b’. The radius of the circle is h.Two diagonals are creating four equal triangles. Each triangle is right-angled triangle, so their area is −Each side of the rhombus is the hypotenuses −So the area of the circle is −Example#include #include using namespace std; float area(float a, float b) {    if (a < 0 || b < 0) //if the values are negative it is invalid       return -1;    float area = (3.1415 ...

Read More
Showing 56391–56400 of 61,248 articles
Advertisements