Found 1401 Articles for C

C/C++ Program to Count number of binary strings without consecutive 1’s?

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

198 Views

A binary number is a number that contains only two i.e. has one or two. Every binary number is A stream of binary bit, and we consider this as a binary string. for this string, we need to find the number of binary string that does not contain consecutive ones That are of N bits.For example, for N - 5 the binary strings satisfy the given constraints are 00000 00001 00010 00100 00101 01000 01001 01010 10000 10001 10010 10100 10101One method is to generate all N-digit strings and print only those strings that satisfy the given constraints. But this ... Read More

C/C++ Program to the Count Inversions in an array using Merge Sort?

sudhir sharma
Updated on 19-Aug-2019 07:40:46

215 Views

The Count of inversions that take place to Sort the given array is known as inversion count. the inversion problem is a classical problem that can be solved using the merge sort Algorithm. in this problem v we will count all elements more than it to its left and add the count to output. ThisLogic is done inside merge function of merge sort.For understanding the topic better let us take an example. Let us consider two sub-arrays involved in merge process -  Input: arr[] = { 1, 9, 6, 4, 5} Output: Inversion count is 5ExplanationInversion count of an arrayGiven an ... Read More

C/C++ Program to check whether it is possible to make the divisible by 3 number using all digits in an array?

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

274 Views

To check whether a number is divisible by 3, we add all the digits of the number and then calculate that the sum is divisible by 3 or not. In this problem, there is an array of integers arr[], and we have to check if a number formed with these number is divisible by 3. If the number formed is divisible then print ‘yes’ else print ‘no’Input: arr[] = {45, 51, 90} Output: YesExplanationconstruct a number which is divisible by 3, for example, 945510.So the answer will be Yes Find the remainder of the sum when divided by 3 true ... Read More

C/C++ Program for the Triangular Matchstick Number?

sudhir sharma
Updated on 19-Aug-2019 07:33:21

155 Views

A triangle that is made by using matchsticks arrange to make an equilateral triangle, this is called the triangular matchstick number. Triangular matchstick number is the number of matchsticks required to make the matchstick triangle.In this problem, we have the number is the floor of a matchstick pyramid, X. and our task is to write a program to print the total minimum number of matchstick required to form a pyramid of matchsticks of x floors.Let's look at an example that will make the concept more clear, Input: 7 Output: 84ExplanationThis is an extension of triangular numbers. For integer X, the ... Read More

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

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

359 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 the Modular Equations?

sudhir sharma
Updated on 19-Aug-2019 07:24:21

305 Views

In mathematics, a modular equation is an algebraic equation satisfied by moduli, in the sense of moduli problem. That is, given a number of functions on a moduli space, a modular equation is an equation holding between them, or in other words an identity for moduli.The most frequent use of the term modular equation is in relation to the moduli problems for elliptic curves. In that case, the moduli space itself is of dimension one. That implies that any two rational functions F and G, in the function field of the modular curve, will satisfy a modular equation P(F, G) ... Read More

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

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

80 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

284 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

197 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

159 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

Advertisements