Programming Articles - Page 2480 of 3366

C++ Program for the Cocktail Sort?

sudhir sharma
Updated on 19-Aug-2019 12:47:46

322 Views

Cocktail sort is a variation of bubble sort that is both a stable sorting algorithm and a comparison sort also known as bidirectional bubble sort, cocktail shaker sort, shaker sort (which can also refer to a variant of selection sort), ripple sort, shuffle sort, or shuttle sort. The algorithm differs from a bubble sort in that it sorts in both directions on each pass through the list.Input:53421 Output:12345Explanation In Cocktail, sort array will be consist of the unsorted element. Cocktail sort works in both directions on each pass through the list. It sort array using bubble sorts once forwards and backward.Example#include ... Read More

When to call the Thread.run() instead of Thread.start() in Java?

Vivek Verma
Updated on 14-May-2025 12:15:29

2K+ Views

This article will briefly discuss the run() and start() methods, and also explain when to call run() instead of the start() method. Calling run() Method Instead of start() Usually, to execute a thread, we will call the start() method, and the start method calls run() implicitly, and the contents of the run() method will be executed as a separate thread. We can also call the run() method explicitly instead of the start() method. If we do so, we will be executing the contents of the run method in the current thread but not in a separate one. In this case, the ... Read More

C++ Program for the BogoSort or Permutation Sort?

sudhir sharma
Updated on 19-Aug-2019 12:51:50

858 Views

Bogosort simply shuffles a collection randomly until it is sorted. BogoSort is an ineffective algorithm based permutation and combination that's why it is known Permutation sort. BogoSort is very flop sorting technique which is also known as, shotgun sort, stupid sort, monkey sort, or slow sort. The algorithm successively generates permutations of its input until it finds one that is sorted.Input - 53421 Output - 12345ExplanationIn bogosort array will be consist of unsorted element checking if the array elements are in order, and if it is not, then change the position of array elements, by swapping the elements randomly, and ... Read More

10’s Complement of a decimal number?

sudhir sharma
Updated on 19-Aug-2019 09:16:32

3K+ Views

9’s complement and 10’s complement are used to make the arithmetic operations in digital system easier. These are used to make computational operations easier using complement implementation and usually trade hardware usage to the program.To obtain the 9’s complement of any number we have to subtract the number with (10n – 1) where n = number of digits in the number, or in a simpler manner we have to subtract each digit of the given decimal number from 9.10’s complement, it is relatively easy to find out the 10’s complement after finding out the 9’s complement of that number. We ... Read More

Average of Squares of n Natural Numbers?

sudhir sharma
Updated on 19-Aug-2019 09:10:15

285 Views

Given a number n, we need to find the average of the square of natural Numbers till n. For this we will first The squares of all the numbers till n. then we will add all these squares and divide them by the number n.Input 3 Output 4.666667Explanation12 + 22 + 32 = 1 + 4 + 9 = 14 14/3 = 4.666667Example#include using namespace std; int main() {    long n , i, sum=0 ,d;    n=3;    for(i=1;i

Add 1 to the number represented as array (Recursive Approach)?

sudhir sharma
Updated on 19-Aug-2019 08:59:09

571 Views

Given an array which is a collection of non-negative number represented as an array of digits, add 1 to the number (increment the number represented by the digits ). The digits are stored such that the most significant digit is the first element of the array.To add 1 to the number represented by digitsGiven array from the end, addition means rounding of the last no 4 to 5.If the last elements 9, make it 0 and carry = 1.For the next iteration check carry and if it adds to 10, do the same as step 2.After adding carry, make carry ... Read More

acosh() function for complex number in C++

sudhir sharma
Updated on 19-Aug-2019 08:47:55

139 Views

The acosh() is the inverse hyperbolic cosine function that returns the inverse hyperbolic cosine of the element passed as parameter. this dysfunction can be out operate over complete. all the it are in radians.To use this method over complex numbers in C plus plus we need to define a template which redefines the function over complex numbers.Syntax for the function that is used to calculate the inverse hyperbolic cosine of a complex number and Returns the value −template complex acosh (const complex& z );Now this method will take complex number as an input and returns the Arc hyperbolic cosine of ... Read More

C++ STL asinh() function

sudhir sharma
Updated on 19-Aug-2019 08:45:48

134 Views

The asinh() function is a function of standard C++ library. The asinh(value) is an inverse hyperbolic sine that returns the value of sinh(x) where x is in radian.The function −asinh() ;Parameter to the function, inverse hyperbolic angle in radian . It can be negative, positive or zero. The parameter value can be double, float or long double.Return value − It returns the inverse hyperbolic sine value of the input value. The returned value is in radians.Lets see an example that shows the working of the function −Example#include using namespace std; int main() {    double insinh = 75.0;    double ... Read More

A square matrix as sum of symmetric and skew-symmetric matrix ?

sudhir sharma
Updated on 19-Aug-2019 08:43:39

954 Views

Symmetric Matrix − A matrix whose transpose is equal to the matrix itself. Then it is called a symmetric matrix.Skew-symmetric matrix − A matrix whose transpose is equal to the negative of the matrix, then it is called a skew-symmetric matrix.The sum of symmetric and skew-symmetric matrix is a square matrix. To find these matrices as the sum we have this formula.Let A be a square matrix. then, A = (½)*(A + A`)+ (½ )*(A - A`), A` is the transpose of the matrix.(½ )(A+ A`) is symmetric matrix.(½ )(A - A`) is a skew-symmetric matrix.Example#include using namespace std; ... Read More

Sum of square-sums of first n natural numbers

sudhir sharma
Updated on 19-Aug-2019 08:41:19

432 Views

The sum of square-sums of the first n natural numbers is finding the sum of sum of squares upto n terms. This series finds the sum of each number upto n, and adds this sums to a sum variable.The sum of square-sum of first 4 natural numbers is −sum = (12) + (12 + 22 ) + (12 + 22 + 32) + (12 + 22 + 32 + 42 ) = 1 + 5 + 14 + 30 = 50There are two methods to find the sum of square-sum of first n natural numbers.1) Using the for loop.In this ... Read More

Advertisements