Server Side Programming Articles - Page 2194 of 2650

Baum Sweet Sequence in C Program?

Arnab Chakraborty
Updated on 20-Aug-2019 14:00:18

196 Views

Here we will see the Baum Sweet Sequence. This sequence is one binary sequence. If a number n has an odd number of contiguous 0s, then nth bit will be 0, otherwise nth bit will be 1.We have a natural number n. Our task is to find the n-th term of Baum Sweet sequence. So we have to check whether it has any consecutive block of zeros of odd length.If the number is 4 then the term will be 1, because 4 is 100. So it has two (even) number of zeros.AlgorithmBaumSweetSeqTerm (G, s) −begin    define bit sequence seq ... Read More

Auxiliary Space with Recursive Functions in C Program?

Arnab Chakraborty
Updated on 20-Aug-2019 13:00:00

415 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

Array range queries for elements with frequency same as value in C Program?

Arnab Chakraborty
Updated on 02-Jul-2020 06:56:57

303 Views

Here we will see one interesting problem. We have one array with N elements. We have to perform one query Q as follows −The Q(start, end) indicates that number of times a number ‘p’ is occurred exactly ‘p’ number of times from start to end.So if the array is like: {1, 5, 2, 3, 1, 3, 5, 7, 3, 9, 8}, and queries are −Q(1, 8) − Here the 1 is present once, and 3 is present 3 times. So the answer is 2Q(0, 2) − Here the 1 is present once. So the answer is 1Algorithmquery(s, e) −Begin   ... Read More

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

Arnab Chakraborty
Updated on 20-Aug-2019 12:53:32

149 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

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

Arnab Chakraborty
Updated on 20-Aug-2019 12:44:02

133 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
Updated on 20-Aug-2019 12:38:37

167 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

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

Arnab Chakraborty
Updated on 20-Aug-2019 12:33:28

307 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

Area of largest Circle inscribe in N-sided Regular polygon in C Program?

Arnab Chakraborty
Updated on 20-Aug-2019 12:29:48

224 Views

Here we will see how to get the area of the circle which is inscribed in N-sided regular polygon. The N (number of sides) are given, and each side of the polygon is ‘a’The approach is simple. One N sided polygon can be divided into N equal triangles, the whole angle for each triangle in center is 360/N, so −Example#include #include using namespace std; float area(float n, float a) {    if (n < 0 || a < 0 ) //if the valuse are negative it is invalid       return -1;    float r = a/(2.0*tan((180/n) ... Read More

C Program for area of hexagon with given diagonal length?

Arnab Chakraborty
Updated on 20-Aug-2019 12:23:31

373 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

C Program for area of decagon inscribed within the circle?

Arnab Chakraborty
Updated on 20-Aug-2019 12:19:06

208 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

Advertisements