Found 1339 Articles for C

Biggest Reuleaux Triangle inscribed within a square inscribed in a semicircle in C?

sudhir sharma
Updated on 04-Oct-2019 08:33:33

148 Views

A Reuleaux triangle is a shape formed by using intersection of three circle, in such a way that each having its center on the boundary of the other two circles. Its boundary is a curve of constant width, the simplest and best known such curve other than the circle itself. Constant width means that the separation of every two parallel supporting lines is the same, independent of their orientation. Because all its diameters are the same.The boundary of a Reuleaux triangle is a constant width curve based on an equilateral triangle. All points on a side are equidistant from the ... Read More

Betrothed numbers in C?

sudhir sharma
Updated on 04-Oct-2019 08:30:08

2K+ Views

Betrothed numbers are pair of two numbers in a way that the sum of their divisors when added by is equal to another number.For example (a,  b) are a pair of betrothed numbers if s(a) = b + 1 and s(b) = a + 1, where s(b) is the aliquot sum of b: an equivalent condition is that σ(a) = σ(b) = a + b + 1, where σ denotes the sum-of-divisors function.The first few pairs of betrothed numbers are: (48,  75), (140,  195), (1050,  1925), (1575,  1648), (2024,  2295), (5775,  6128).All known pairs of betrothed numbers have opposite parity. Any pair of the same parity must exceed 1010.AlgorithmStep 1: Find the sum of all divisors for both numbers. Step 2: Finally ... Read More

Array elements that appear more than once in C?

sudhir sharma
Updated on 04-Oct-2019 08:13:33

1K+ Views

Array is a container of elements of Same data types length needs to be defined beforehand. And an element can appear in any order and any number of times in an array. so in this program we will find elements that appear more than once in an array.Problem description − We have given an array arr[] in which we have to find which of the element are repeating in the array an app to print them.Let’s take an example to understand this better.Example, Input: arr[] = {5, 11, 11, 2, 1, 4, 2} Output: 11 2ExplanationWe have an array arr ... Read More

Array sum after dividing numbers from previous in C?

sudhir sharma
Updated on 04-Oct-2019 07:11:11

247 Views

Array is a sequence of elements of same data type. in this problem we are going to consider integer array for solving the problem. in this problem we are going to find sum of Elements found by dividing the element from the element proceeding it.Let’s take a few examples to understand this Problem better −Example 1 −Array : 3 , 5 ,98, 345 Sum : 26Explanation − 3 + 5/3 + 98/5 + 345/98 = 3 + 1 + 19 + 3 = 26We have divided each element with its preceding element and considered only integer parts of the divisions ... Read More

_Generic keyword in C ? 1: 20

sudhir sharma
Updated on 04-Oct-2019 06:59:01

836 Views

_Generic keyword in C is used to define MACRO for different data types. This new keyword was added to the C programming language in C11 standard release. the _Generic keyword is used to help the programmer use the MACRO in a more efficient way.this keyword translate the MACRO based on the type of the variable. let's take an example ,#define dec(x) _Generic((x), long double : decl, \ default : Inc , \ float: incf )(x)The above syntax is how to declare any MACRO as generic for different methods.Let's take an example code, this code will define a MACRO that will ... Read More

Area of squares formed by joining midpoints repeatedly in C?

sudhir sharma
Updated on 03-Oct-2019 13:24:05

126 Views

Area of a square is equal to the product of sides of the square.We are considering a figure in which the midpoints of sides of each square make another square. And so on until a specific number of squares.This figure shows a square made by joining the midpoints of a square.For this figure the let the side be a, The length of side of inner square will beL2 = (a/2)2 + (a/2)2 L2 = a2(1/4 + 1/4) = a2(1/2) = a2/2 L = a2/ (\sqrt{2}).Area of square2 = L2 = a2/2.For the next square, the area of square 3 = ... Read More

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

sudhir sharma
Updated on 03-Oct-2019 13:13:52

262 Views

A rhombus inscribed in a rectangle touches the sides of the rectangle so by this we can infer that the diagonals of the largest inscribed rhombus are equal to the length and breadth of the rectangle.If we have the length(l) and breadth(b) of the rectangle, the length of the diagonal of the largest rhombus inscribed inside it is d1 = l and d2 = b.The area of a rhombus is given by the formula, Area = (d1*d2)/2Putting the values of d1 and d2. We get, Area = (l*b)/2Using this formula we can create a program that calculates the area of ... Read More

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

sudhir sharma
Updated on 03-Oct-2019 13:10:41

2K+ Views

A circle inscribed in a rectangle touches the larger side of the rectangle with its ends i.e. the length is tangent to the circle.A rectangle inscribed in a semicircle touches its arc at two points. The breadth of the rectangle is equal to the diameter of the circle.If R is the radius of semi-circle.Length of the rectangle = √2R/2Breadth of the rectangle = R/√2Radius of biggest circle inscribed isr = b/2 = R/2√2Using this formula we can find the area of this circle inscribed in a rectangle which is inscribed in a semicircle, Area = (π*r2) = π*R/8Example Live Demo#include ... Read More

A Product Array Puzzle in C?

sudhir sharma
Updated on 03-Oct-2019 12:51:23

343 Views

An array is a container of elements of the same data types. In product array Puzzle, the product of all elements is found.In this Product Array Puzzle, we need to find the product of all elements of the array except element. The condition is that you cannot use the division operator and store this to another array.For solving this we will be creating two products, one for all left elements and one for all right elements. And then adding this left and right products to get the desired products.Example Live Demo#include #include void productfind(int arr[], int n) {    int *left ... Read More

Deep Copy of Struct Member Arrays in C

Narendra Kumar
Updated on 26-Sep-2019 13:44:41

2K+ Views

Structure allows us to create user defined datatype. Structure member can be primitive datatype or it can be an array of statically allocated memory. When we assign one structure variable to another then shallow copy is performed. However, there is an exception, if structure member is an array then compiler automatically performs deep copy. Let us see this with example −Example Live Demo#include #include typedef struct student {    int roll_num;    char name[128]; } student_t; void print_struct(student_t *s) {    printf("Roll num: %d, name: %s", s->roll_num, s->name); } int main() {    student_t s1, s2;    s1.roll_num = ... Read More

Advertisements