Found 1339 Articles for C

Area of Reuleaux Triangle?

Arnab Chakraborty
Updated on 01-Aug-2019 07:33:44

470 Views

Here we will see how to calculate the area of Reuleaux Triangle like below. The Reuleaux Triangle has one equilateral triangle inside it. Suppose its height is h, this shape is made by the intersection of three circles.There are three circular sectors. The area of each sector is −Since the area of the equilateral triangle is added three times, then we have to subtract them. So the final area is −Example#include #include using namespace std; float areaReuleaux(float h) {    if (h < 0) //if h is negative it is invalid    return -1;    float area = ... Read More

Area of a n-sided regular polygon with given Radius?

Arnab Chakraborty
Updated on 01-Aug-2019 07:30:04

266 Views

Here we will see how to get the area of an n-sided regular polygon whose radius is given. Here the radius is the distance from the center of any vertex. To solve this problem, we have drawn one perpendicular from the center to one side. Let each side is of length ‘a’. The perpendicular is dividing the side into two parts. The length of each part is a/2. The perpendicular and one radius is making an angle x. Let the length of the radius is h.Here we can see that the polygon is divided into N equal triangles. So for ... Read More

Area of a leaf inside a square?

Arnab Chakraborty
Updated on 01-Aug-2019 07:26:47

1K+ Views

Here we will see how to get the area of a leaf-like below, which is present inside the square ABCD. Each side of the square is of length ‘a’.The leaf has two equal parts. Area of each part is said p, now −And the area of the full leaf is 2p.Example#include using namespace std; float leafArea(float a){    return (a * a * (3.1415/2 - 1)); } int main() {    float square_side = 7.0f;    cout

Area of a circle inscribed in a rectangle which is inscribed in a semicircle?

Arnab Chakraborty
Updated on 31-Jul-2019 13:38:21

162 Views

Let us consider one semicircle is given. Its radius is R. One rectangle of length l and breadth b is inscribed in that semi-circle. Now one circle with radius r is inscribed in the rectangle. We have to find the area of the inner circle.As we know biggest rectangle that can be inscribed within the semi-circle has length l and breadth b, then the equation of l and b will be like following −Now, the biggest circle that can be inscribed within the rectangle has radius r is like below −Example#include #include using namespace std; float innerCircleArea(float R){ ... Read More

Arc length from given Angle?

Arnab Chakraborty
Updated on 31-Jul-2019 13:33:53

176 Views

Here we will see how to get the arc length from the given angle. One circle is given. The radius of the circle is given. Our task is to get the arc length using the radius and the angle. The angle is in degree.Here r and x is given. We have to find the value of L. The formula is like below −𝐿 = 2𝜋𝑟 ∗ (𝑥/360)Example#include using namespace std; float getArcLength(float r, float x){    return (2 * 3.1415f * r) * (x / 360.0f); } int main() {    float rad = 12.0f;    float angle = 45.0f;    cout

An interesting solution to get all prime numbers smaller than n?

Arnab Chakraborty
Updated on 02-Jul-2020 09:40:59

162 Views

Here we will see how to generate all prime numbers that are less than n in an efficient way. In this approach we will use the Wilson’s theorem. According to his theorem if a number k is prime, then ((k - 1)! + 1) mod k will be 0. Let us see the algorithm to get this idea.This idea will not work in C or C++ like language directly, because it will not support the large integers. The factorial will generate large numbers.AlgorithmgenAllPrime(n)Begin    fact := 1    for i in range 2 to n-1, do       fact ... Read More

An Interesting Method to Generate Binary Numbers from 1 to n?

Arnab Chakraborty
Updated on 02-Jul-2020 09:41:31

465 Views

Here we will see one interesting method for generating binary numbers from 1 to n. Here we are using queue. Initially the queue will hold first binary number ‘1’. Now repeatedly delete element from queue, and print it, and append 0 at the end of the front item, and append 1 at the end of the front time, and insert them into the queue. Let us see the algorithm to get the idea.AlgorithmgenBinaryNumbers(n)Begin    define empty queue.    insert 1 into the queue    while n is not 0, do       delete element from queue and store it ... Read More

An efficient way to check whether n-th Fibonacci number is multiple of 10?

Arnab Chakraborty
Updated on 31-Jul-2019 13:20:58

253 Views

Here we will see one efficient way to check whether the nth Fibonacci term is multiple of 10 or not. Suppose the Fibonacci terms are {0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987}. So here 15th (Counting from 0) Fibonacci term is divisible by 10. For 16 it will return true.One easiest method is generating Fibonacci numbers up to given term, and check whether it is divisible by 10 or not? But this solution is not good, because it will not work for larger terms.Another good approach is like below −Fibonacci terms ... Read More

Amazing stuff with system() in C / C++?

Arnab Chakraborty
Updated on 31-Jul-2019 13:18:06

872 Views

Here we will see some amazing results by using the system() function in C or C++. The system function is present in Windows, Linux and MAC operating systems. This function is used to execute the system commands that can be written in Command line.Here we will see two usages if system function in C or C++. The first one is getting the IP configuration details using C++ program.Example#include #include using namespace std; int main() {    system("C:\Windows\System32\ipconfig"); }OutputWindows IP Configuration Ethernet adapter Local Area Connection:    Connection-specific DNS Suffix . : domain.name    Link-local IPv6 Address . . ... Read More

All possible strings of any length that can be formed from a given string?

Arnab Chakraborty
Updated on 31-Jul-2019 13:14:53

746 Views

In this section we will see how to generate all possible strings of any length, this will take each combination of characters to make string. For example, if the string is ABC, then it will generate − {A, B, C, AB, BA, BC, CB, CA, AC, ABC, ACB, BAC, BCA, CAB, CBA}Let us see the example to get the idea.AlgorithmprintAllString(str)Begin    n := length of the string str    count is 2^n – 1    for each number 0 to count, do       sub_str := empty string       for j in range 0 to n, do ... Read More

Advertisements