Found 1339 Articles for C

Binary Search for Rational Numbers without using floating point arithmetic in C program

sudhir sharma
Updated on 22-Nov-2019 09:16:45

249 Views

In this problem, we are given a sorted array of rational numbers. and we have to search the given element using binary search algorithm for this rational number array without using floating point arithmetic.A Rational number is number represented in the form p/q where both p and q are integers. For example, ⅔, ⅕.Binary search is searching technique that works by finding the middle of the array for finding the element.for finding the element using binary search from a sorted array of rational numbers, where floating point arithmetic are not allowed. We will compare the numerators and denominators to find ... Read More

C program to delete a file

sudhir sharma
Updated on 22-Nov-2019 07:40:35

3K+ Views

In programming, working with files is very important and every programming language has its own set of functions or library that help in manipulation of files.In C Programming Language also there is a function remove which can be used by the programmer to delete a file.remove() function in c programmingThe remove function is used to delete the file whose name is specified. This function is in the stdio header file.Syntaxremove (“file_name”);ParametersThe function accepts one parameter which is the name of the file that is to be deleted.File name can also be the path to the file but only if the ... Read More

C program to find the Roots of Quadratic equation

Ayush Gupta
Updated on 09-Jul-2020 08:55:12

3K+ Views

In this tutorial, we will be discussing a program to find the roots of the Quadratic equation.Given a quadratic equation of the form ax2 + bx + c. Our task is to find the roots x1 and x2 of the given equation.For this, we are using the deterministic method, in thisD = √b2 - 4acthen the roots of the equation will bex1 = (-b + D)/2a ,andx2 = (-b - D)/2aExample#include #include #include //calculating the roots of equation void calc_roots(int a, int b, int c) {    if (a == 0) {       printf("Invalid Equation");       ... Read More

C Program for Hexagonal Pattern

Sunidhi Bansal
Updated on 21-Nov-2019 12:28:19

2K+ Views

We are given with an integer ‘n’ and the task is to generate the hexagonal pattern and display the final output.ExampleInput-: n=5 Output-:Input-: n = 4 Output-:Approach we are using in the given program is as follows −Input the number ‘n’ from userDivide the entire pattern into three parts i.e. upper part, middle part and lower part Start loop i for printing the upper part of the pattern from i to 0 and i to be less than n and keep incrementing the value of i Start loop m for printing the middle part of the pattern from m to ... Read More

C Program for Circumference of a Parallelogram

Sunidhi Bansal
Updated on 09-Jul-2020 08:45:53

189 Views

We are given with the sides of parallelogram and the task is to generate the circumference of a parallelogram with its given sides and display the resultWhat is a Parallelogram?Parallelogram is a type of quadratic which have −Opposite sides parallelOpposite angles equalPolygon diagonals bisects each otherShown in the below figure ‘a’ and ‘b’ are the sides of a parallelogram where parallel sides are shown in the figure.Perimeter/Circumference of a parallelogram is defined as −Circumference of Parallelogram = 2(a + b)                                           ... Read More

C program for Binomial Coefficients table

Sunidhi Bansal
Updated on 09-Jul-2020 08:48:19

8K+ Views

Given with a positive integer value let’s say ‘val’ and the task is to print the value of binomial coefficient B(n, k) where, n and k be any value between 0 to val and hence display the result.What is Binomial CoefficientBinomial coefficient (n, k) is the order of choosing ‘k’ results from the given ‘n’ possibilities. The value of binomial coefficient of positive n and k is given by$$C_k^n=\frac{n!}{(n-k)!k!}$$where, n >= kExampleInput-: B(9, 2) Output-:$$B_2^9=\frac{9!}{(9-2)!2!}$$ $$\frac{9\times 8\times 7\times 6\times 5\times 4\times 3\times 2\times 1}{6\times 5\times 4\times 3\times 2\times 1)\times 2\times 1}=\frac{362, 880}{1440}=252$$What is Binomial Coefficient TableThe Binomial Coefficient Table is formed ... Read More

C Program for sum of cos(x) series

Sunidhi Bansal
Updated on 20-Nov-2019 12:23:00

5K+ Views

We are given with the value of x and n where, x is the angle for cos and n is the number of terms in the cos(x) series.For Cos(x)Cos(x) is a trigonometric function which is used to calculate the value of x angle.Formula$$\cos (x) = \displaystyle\sum\limits_{k=0}^\infty \frac{(-1)^{k}}{(2k!)}x^{2k}$$For Cos(x) seriesCos(x) = 1 – (x*2 / 2!) + (x*4 / 4!) – (x*6 / 6!) + (x*8 / 8!)……ExampleInput-: x = 10, n = 3 Output-: 0.984804 Input-: x = 8, n = 2 Output-: 0.990266Approach used in the below program is as follows −Input the value of x and nApply the ... Read More

C Program for nth Catalan Number

Sunidhi Bansal
Updated on 20-Nov-2019 12:19:33

2K+ Views

Given an interger n; the task is to find the Catalan Number on that nth position. So, before doing the program we must know what is a Catalan Number?Catlan numbers are the sequence of natural numbers, which occurs in the form of various counting number problems.Catalan numbers C0, C1, C2, … Cn are driven by formula −$$c_{n}=\frac{1}{n+1}\binom{2n}{n} = \frac{2n!}{(n+1)!n!}$$The few Catalan numbers for every n = 0, 1, 2, 3, … are 1, 1, 2, 5, 14, 42, 132, 429, 1430, 4862, …So if we entered n =3 we should get 5 as an output from the programSome of few ... Read More

C Program that receives a number and prints it out in large size

Sunidhi Bansal
Updated on 20-Nov-2019 11:53:00

411 Views

Given a number n in form of a string; the task is to print that following number in large using hash symbols.Like we have provided a number “1234”The representation of the following number should be −Likewise we want our solution to be printed −ExampleInput: n[] = {“2234”} Output:Input: n[] = {“987”} Output:Approach we will be using to solve the given problem −Take at most 4 digit number a input in a string.Make arrays of every number one by one the large pattern we want for the number.Traverse the string and print every number one by one.AlgorithmStart    Step 1 -> ... Read More

C Program to check if a number belongs to a particular base or not

Sunidhi Bansal
Updated on 20-Nov-2019 11:27:45

980 Views

Given a number as a string and a base; the task is to check whether the given number of is of that given base or not.We have to check the number and the base according to the number system in which there are bases like 2 for a binary number, 8 for an octal number, 10 for decimal number and 16 for a Hexadecimal number. According to this we have to find whether the given number in a string belongs to a particular base or not, If it belongs to a particular base then we have to print “Yes” on ... Read More

Advertisements