Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Programming Articles
Page 664 of 2544
Generic keyword in C ?
As we know that the Macros are used in C or C++, but there is no facility for type checking. The macros can take any type of argument in it. The following example will show this case clearly.Example#include #define INCREMENT(X) ++X main() { int x = 5; float y = 2.56; char z = 'A'; printf("Integer Increment: %d", INCREMENT(x)); printf("Float Increment: %f", INCREMENT(y)); printf("Character Increment: %c", INCREMENT(z)); }OutputInteger Increment: 6 Float Increment: 3.560000 Character Increment: BThat is the problem of macro. In the later version of C, we can use macro by using ‘_Generic’ keyword. Using ...
Read MoreC Program for replacing one digit with other
Given a number n, we have to replace a digit x from that number with another given number m. we have to look for the number whether the number is present in the given number or not, if it is present in the given number then replace that particular number x with another number m.Like we are given with a number “123” and m as 5 and the number to be replaced i.e. x as “2”, so the result should be “153”.ExampleInput: n = 983, digit = 9, replace = 6 Output: 683 Explanation: digit 9 is the first digit ...
Read MoreAliquot Sequence in C++
Aliquot sequence is a special sequence of numbers. The sequence starts from the number itself and the next number of the sequence is the sum of the proper divisors of the previous terms.Let’s take an example of the sequence to learn the concept better −Input : 8 Output : 8 7 1 0 Explanation : Proper divisors of 8 are 4, 2, 1. The sum is 7 Proper divisors of 7 are 1. The sum is 1 Proper divisors of 1 are 0. The sum is 0Perfect number is the number that has the aliquot sequence of ...
Read MoreA backtracking approach to generate n bit Gray Codes ?
In this section we will see how we can generate the gray codes of n bits using backtracking approach? The n bit gray code is basically bit patterns from 0 to 2^n – 1 such that successive patterns differ by one bit. So for n = 2, the gray codes are (00, 01, 11, 10) and decimal equivalent is (0, 1, 3, 2). The program will generate the decimal equivalent of the gray code values.AlgorithmgenerateGray(arr, n, num)begin if n = 0, then insert num into arr return end if generateGray(arr, n-1, ...
Read MoreC Program to check if a number is divisible by sum of its digits
Given a number n we have to check whether the sum of its digits divide the number n or not. To find out we have to sum all the numbers starting from the unit place and then divide the number with the final sum.Like we have a number “521” so we have to find the sum of its digit that will be “5 + 2 + 1 = 8” but 521 is not divisible by 8 without leaving any remainder.Let’s take another example “60” where “6+0 = 6” which can divide 60 and will not leave any remainder.ExampleInput: 55 Output: ...
Read MoreA permutation where each element indicates either number of elements before or after it?
In this section we will see one problem. Here n elements are given in an array. We have to check whether there is a permutation of that array exists, such that each element indicates the number of elements present either before or after it.Suppose the array elements are {2, 1, 3, 3}. The appropriate permutation is like {3, 1, 2, 3}. Here the first 3 is indicating there are three elements next of it, the 1 indicates there is only one element before this. The 2 indicates there are two elements before it and the last 3 indicates that there ...
Read MoreAnonymous classes in C++
Anonymous entity is anything that is defined without a name. A class with no name provided is known as an anonymous class in c++. An anonymous class is a special class with one basic property.As there is no name given to the class there is no constructor allocated to it, though a destructor is there for deallocating the memory block.The class cannot be used as an element of a function i.e. you cannot pass it as an argument or cannot accept values return from the function.The syntax for defining an anonymous class in c++class { //data members // ...
Read MoreAdding elements of an array until every element becomes greater than or equal to k in C++.
Array − An array is a container of elements of the same data type, whose elements are 0 indexed.In this problem, we will use an array of integers. And check if all the elements are greater than the given number or not. Here we will check if all elements of the array are greater than or equal to a given number k. If not then we will add two minimum elements of the array and treat this sum as a single element. And then again check for the same condition for the new array. If the condition comes out to ...
Read MoreA sorting algorithm that slightly improves on selection sort?
Here we will see some improvements on selection sort. As we know that the selection sort works by taking either the minimum or maximum element from the array and place that element at correct position. In this approach, we want to sort the array in both ways. Here we will take the max and min simultaneously, then sort the array from two end. Let us see the algorithm to get better idea.AlgorithmtwoWaySelectionSort(arr, n)begin for i := 0, and j := n-1, increase i by 1, and decrease j by 1, until i>=j, do min := minimum ...
Read MoreAbsolute difference between sum and product of roots of a quartic equation?
In this section we will see how to get the absolute difference between the sum of the roots and the products of the root of a quartic equation?The quartic equation is like 𝑎𝑥4+𝑏𝑥3+𝑐𝑥2+𝑑𝑥+𝑒We can solve the equation and then try to get the product and sum of the roots by some normal process, but that takes much time and that approach is not so efficient. In this kind of equation, we have two formulae. The Sum of roots are always −𝑏∕𝑎 and the product of roots are always 𝑒∕𝑎 . So we have to find only the value of ∣−𝑏∕𝑎− ...
Read More