Found 34484 Articles for Programming

C++ Program to Implement Radix Sort

Nancy Den
Updated on 30-Jul-2019 22:30:25

4K+ Views

Radix sort is non-comparative sorting algorithm. This sorting algorithm works on the integer keys by grouping digits which share the same position and value. The radix is the base of a number system. As we know that in decimal system the radix or base is 10. So for sorting some decimal numbers, we need 10 positional box to store numbers.The complexity of Radix Sort TechniqueTime Complexity: O(nk)Space Complexity: O(n+k)Input − The unsorted list: 802 630 20 745 52 300 612 932 78 187 Output − Data after Sorting: 20 52 78 187 300 612 630 745 802 932AlgorithmradixSort(array, size, maxDigit)Input: ... Read More

C++ Program to Find Fibonacci Numbers using Dynamic Programming

Nancy Den
Updated on 30-Jul-2019 22:30:25

3K+ Views

The Fibonacci sequence is like this, 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, ……In this sequence the nth term is the sum of (n-1)th and (n-2)th terms.To generate we can use the recursive approach, but in dynamic programming the procedure is simpler. It can store all Fibonacci numbers in a table, by using that table it can easily generate the next terms in this sequence.Input − Take the term number as an input. Say it is 10Output − The 10th fibinacci term is 55AlgorithmgenFiboSeries(n)Inputmax number of terms.OutputThe nth Fibonacci term.Begin define array named fibo of size ... Read More

C++ program to convert Fahrenheit to Celsius

George John
Updated on 30-Jul-2019 22:30:25

3K+ Views

In this program we will see how to convert Celsius to Fahrenheit using C++. As we know the formula is simple.AlgorithmBegin Take the Celsius temperature in C calculate F = (9C/5)+32 return F EndExample Code#include using namespace std; main() { float f, c; cout > c; f = (9.0*c/5.0)+32; cout

C++ program to generate random number

Chandu yadav
Updated on 30-Jul-2019 22:30:25

4K+ Views

Let us see how to generate random numbers using C++. Here we are generating a random number in range 0 to some value. (In this program the max value is 100).To perform this operation we are using the srand() function. This is in the C library. The function void srand(unsigned int seed) seeds the random number generator used by the function rand.The declaration of srand() is like belowvoid srand(unsigned int seed)It takes a parameter called seed. This is an integer value to be used as seed by the pseudo-random number generator algorithm. This function returns nothing.To get the number we ... Read More

C++ Program that will fill whole memory

George John
Updated on 30-Jul-2019 22:30:25

231 Views

In this article we will see how to fill the whole memory by writing a simple C++ program. Here the logic is very simple. We shall create new integer variables by using the dynamic memory allocation. If we create some variables again and again, it will fill the entire primary memory.In C++ to dynamically allocate a memory space we can use the new keyword.The basic syntax of the new operator is like below.pointer_var = new data_typeTo deallocate the memory space, we can use the delete keyword. The syntax isdelete pointer_varNote After running this program it may slow down the performance ... Read More

C++ Program to Print “Even” or “Odd” without using conditional statement

Chandu yadav
Updated on 30-Jul-2019 22:30:25

3K+ Views

In this section we will see how to check whether a number is odd or even without using any kind of conditional statements like (=, ==).We can easily check the odd or even by using the conditional statements. We can divide the number by 2, then check whether the remainder is 0 or not. if 0, then it is even. Otherwise we can perform AND operation with the number and 1. If the answer is 0, then it is even, otherwise odd.Here no conditional statements can be used. We will see two different methods to check the odd or even.Method ... Read More

Rules for operator overloading in C++

Arjun Thakur
Updated on 30-Jul-2019 22:30:25

14K+ Views

In C++ it supports compile time polymorphism. The examples of compile time polymorphism are the function overloading and the operator overloading.There are some rules for the operator overloading. These rules are like belowOnly built-in operators can be overloaded. If some operators are not present in C++, we cannot overload them.The arity of the operators cannot be changedThe precedence of the operators remains same.The overloaded operator cannot hold the default parameters except function call operator “()”.We cannot overload operators for built-in data types. At least one user defined data types must be there.The assignment “=”, subscript “[]”, function call “()” and ... Read More

Unordered_multimap operator= in C++

George John
Updated on 30-Jul-2019 22:30:25

50 Views

The C++ function std::unordered_multimap::operator=() assigns new contents to the unordered_multimap by replacing old ones and modifies size if necessary.Following is the declaration for std::unordered_multimap::operator=() function form std::unordered_map() header.C++11 (Syntax)unordered_multimap& operator=(const unordered_multimap& umm);Parametersumm - Another unordered_multimap object of same type.Return ValueReturns this pointer.Example Code#include #include using namespace std; int main(void) {    unordered_multimap umm1 = {       {'a', 1},       {'b', 2},       {'c', 3},       {'d', 4},       {'e', 5},    };    unordered_multimap umm2;    umm2 = umm1;    cout

Overloading stream insertion (<<) and extraction (>>) operators in C++

Chandu yadav
Updated on 30-Jul-2019 22:30:25

8K+ Views

C++ is able to input and output the built-in data types using the stream extraction operator >> and the stream insertion operator and insertion operator

Operators that cannot be overloaded in C++

Arjun Thakur
Updated on 30-Jul-2019 22:30:25

10K+ Views

In C++ we can overload some operators like +, -, [], -> etc. But we cannot overload any operators in it. Some of the operators cannot be overloaded. These operators are like below? “.” Member access or dot operator? “? : ” Ternary or conditional operator? “::” Scope resolution operator? “.*” Pointer to member operator? “sizeof” The object size operator? “typeid” Object type operatorThese operators cannot be overloaded because if we overload them it will make serious programming issues.For an example the sizeof operator returns the size of the object or datatype as an operand. This is evaluated by the ... Read More

Advertisements