C Articles - Page 85 of 134

C/C++ Program for the Odd-Even Sort (Brick Sort)?

sudhir sharma
Updated on 19-Aug-2019 07:26:35

510 Views

The odd-even sword also known as the brick sort is a similar sorting technique, like bubble sort. This sorting technique is subdivided into 2 phases odd phase and even phase, Both these phases simultaneously at every iteration until all the elements get sorted.The Odd phase of this programming technique works as a bubble sort but only on the elements that have an odd index.Similarly, the even phase works only on the elements that have an even index.For making this concept more clear let's take an example :Input: a[]={3, 5, 7, 6, 1, 4, 2} Output: 1 2 3 4 5 ... Read More

C/C++ Program for Number of solutions to Modular Equations?

sudhir sharma
Updated on 19-Aug-2019 07:17:42

153 Views

We have an n number of coins and we have to French the coin way that it makeup Pyramid of maximum height. We will arrange the first coin in First row second and third coin in the second row and so onIn the given diagram, we make pyramid 6 of coins having a height of 3. We cannot make height 4 but we will need 10 coins. It is simple to get the height by using this formula;H = {(-1+ √(1+8N))/2}Input: n = 10 Output: Height of pyramid: 4ExplanationHeight by using this formulaH = {(-1+ √(1+8N))/2}Example#include #include using ... Read More

C/C++ Program for Finding the vertex, focus and directrix of the parabola?

sudhir sharma
Updated on 19-Aug-2019 07:14:05

409 Views

A set of points on a plain surface that forms a curve such that any point on that curve is equidistant from a point in the center (called focus) is a parabola.The general equation for the parabola isy = ax2 + bx + cThe vertex of a parabola is the coordinate from which it takes the sharpest turn whereas a is the straight-line used to generate the curve.Focus is the point with is equidistant from all points of the parabola.Here, we will find the vertex, focus, and directrix of a parabola. There is a mathematical formula that finds all these ... Read More

Average numbers in array in C Programming

sudhir sharma
Updated on 01-Jul-2020 12:08:59

284 Views

There are n number of elements stored in an array and this program calculates the average of those numbers. Using different methods.Input - 1 2 3 4 5 6 7Output - 4Explanation - Sum of elements of array 1+2+3+4+5+6+7=28No of element in array=7Average=28/7=4There are two methodsMethod 1 −IterativeIn this method we will find sum and divide the sum by the total number of elements.Given array arr[] and size of array nInput - 1 2 3 4 5 6 7Output - 4Explanation - Sum of elements of array 1+2+3+4+5+6+7=28No of element in array=7Average=28/7=4Example#include using namespace std; int main() {    int arr[] = { 1, 2, 3, ... Read More

Add minimum number to an array so that the sum becomes even in C programming

sudhir sharma
Updated on 09-Aug-2019 13:22:25

235 Views

Given an array, add the minimum number (which should be greater than 0) to the array so that the sum of array becomes even.Input - 1 2 3 4, Output - 2Explanation - Sum of array is 10, so we add minimum number 2 to make the sum even.Method 1: calculate the sum of all elements of the array, then check if the sum is even then add minimum number is 2, else add minimum number is 1.Input - 1 2 3 4, Output - 2Explanation - Sum of array is 10, so we add minimum number 2 to make the sum even.Example#include using namespace std; int ... Read More

Arithmetic Mean in C programming

sudhir sharma
Updated on 09-Aug-2019 13:15:22

3K+ Views

Arithmetic mean is the sum of a collection of numbers divided by the number of numbers in the collection.Basic properties of Arithmetic MeanThe mean of n numbers x1, x2, . . ., xn is x. If each observation is increased by p, the mean of the new observations is (x + p).The mean of n numbers x1, x2, . . ., xn is x. If each observation is decreased by p, the mean of the new observations is (x - p).The mean of n numbers x1, x2, . . ., xn is x. If each observation is multiplied by a nonzero ... Read More

C Program for Tower of Hanoi

sudhir sharma
Updated on 01-Jul-2020 11:35:25

13K+ Views

The tower of Hanoi is a mathematical puzzle. It consists of three rods and a number of disks of different sizes which can slide onto any rod. The puzzle starts with the disks in a neat stack in ascending order of size on one rod, the smallest at the top. We have to obtain the same stack on the third rod.The objective of the puzzle is to move the entire stack to another rod, obeying the following simple rules−Only one disk can be moved at a time.Each move consists of taking the upper disk from one of the stacks and ... Read More

C/C++ Program for nth Catalan Number?

sudhir sharma
Updated on 13-Aug-2019 06:45:25

613 Views

Catalan numbers are a sequence of numbers. Catalan numbers form a sequence of natural numbers that occur in various counting problems, often involving recursively-defined objects.Cn is the number of Dyck words of length 2n. A Dyck word is a string consisting of n X's and n Y's such that no initial segment of the string has more Y's than X's. For example, the following are the Dyck words of length 6XXXYYY XYXXYY XYXYXY XXYYXY XXYXYY.Re-interpreting the symbol X as an open parenthesis and Y as a close parenthesis, Cn counts the number of expressions containing n pairs of parentheses which ... Read More

C Program to Multiply two Floating Point Numbers?

sudhir sharma
Updated on 01-Jul-2020 11:36:53

770 Views

Float is a shortened term for "floating-point." By definition, it's a fundamental data type built into the compiler that's used to define numeric values with floating decimal points. A floating-point type variable is a variable that can hold a real number, such as 4320.0, -3.33, or 0.01226. The floating part of the name floating point refers to the fact that the decimal point can “float”; that is, it can support a variable number of digits before and after the decimal point.floating pointCategoryTypeMinimum SizeTypical Sizefloating pointfloat4 bytes4 bytesdouble8 bytes8 byteslong double8 bytes8, 12, or 16 bytesFloating-point rangeSizeRangePrecision4 bytes±1.18 x 10-38 to ... Read More

C program to find the length of a string?

sudhir sharma
Updated on 01-Jul-2020 11:38:51

690 Views

The string is actually a one-dimensional array of characters which is terminated by a null character '\0'. Thus a null-terminated string contains the characters that comprise the string followed by a null.To find the length of a string we need to loop and count all words in the loop until the ‘\0’ character is matched.For exampleInput −naman Output − string length is 5Explanation − we need to iterate over each index of the string until reach the end of string means ‘\0’ which is the null character. Example#include #include int main() {    char string1[]={"naman"};    int i=0, length;    while(string1[i] !='\0') ... Read More

Advertisements