Programming Articles - Page 1994 of 3366

Place K-knights such that they do not attack each other in C++

sudhir sharma
Updated on 17-Apr-2020 10:43:06

602 Views

In this problem, we are given three integer value K, N, M. our task is to place K knights in an NxM chessboard such that no two knights attack each other. There can be cases with 0 valid ways and also cases with multiple valid ways. You need to print all valid cases.Knight is a chess piece that moves two moves ahead and then one move to the left of right. It can move in any direction in the chessboard.Attack is the position when one piece can be in the same place as other pieces in one chance of its ... Read More

Place N^2 numbers in matrix such that every row has an equal sum in C++

sudhir sharma
Updated on 17-Apr-2020 10:39:25

200 Views

In this problem, we are given an integer value N. our task is to print numbers within the range (1, N2) in a 2D matrix of size NxN in such a way that the sum elements of each row are equal.Let’s take an example to understand the problem, Input − N = 4Output −1 6 11 16 2 7 12 13 3 8  9 14 4 5 10 15Sum of elements in each row is 34To solve this method, we need to place each element in the matrix in such a way that the total in each row is equal. ... Read More

Playing with Destructors in C++

sudhir sharma
Updated on 17-Apr-2020 10:35:34

995 Views

Destructor is a function of a class in c++ that does the job of deleting the object of a class.Calling a destructorDestructor is called when the object of a class goes out of the scope in the program. The cases when object goes out of scope, The program goes out of the scope of a function.The program ends.The block initializing local variables of object goes out of scope.When the operator of the object is deleted.ExampleLet’s see a code and guess the output of the program,  Live Demo#include using namespace std; int i; class destructor {    public:     ... Read More

Quickly merging two sorted arrays using std::merge() in C++ STL(cute ho ap)

Sunidhi Bansal
Updated on 17-Apr-2020 15:40:02

2K+ Views

In this article we will be discussing how we can quickly merge two sorted arrays using std::merge() function in C++ STL.So, before solving the problem let's first discuss the std::merge() in C++ STL.What is std::merge()?std::merge() function is an inbuilt function in C++ STL, which is defined in the header file. merge() is used to merge two sorted ranges or series. This function combines two sorted ranges to make one single sorted range. All the elements are compared using less than operator (

quick_exit() function in C++ with Examples

Sunidhi Bansal
Updated on 17-Apr-2020 10:01:01

249 Views

In this article we will be discussing the working, syntax and examples of quick_exit() function in C++ STL.What is quick_exit()?quick_exit() function is an inbuilt function in C++ STL, which is defined in the header file. quick_exit() function is used to quickly terminate the calling process means it terminates the process without cleaning of its resources.This function is used for normal termination and no additional cleanup tasks are being performed like, no object destructors are called, whereas the C streams are closed or flushed, the files which are opened with tmpfile are being removed.When we terminate a process using quick_exit() ... Read More

putwchar() function in C/C++

Sunidhi Bansal
Updated on 17-Apr-2020 09:58:18

125 Views

In this article we will be discussing the working, syntax and examples of putwchar() function in C++ STL.What is putwchar()?putwchar() function is an inbuilt function in C++ STL, which is defined in the header file. putwchar() function is used to write the wide character on the standard output device. This function takes the wide character from the arguments and writes it on the stdout or standard output of the system.This function is a wide character version of putchar() which is defined in the header file.Syntaxputwchar( wchar_t widec );ParametersThe function accepts following parameter(s) −widec − The wide character which ... Read More

mbrtoc32() in C/C++ with Examples

Sunidhi Bansal
Updated on 17-Apr-2020 09:54:48

228 Views

In this article we will be discussing the working, syntax and examples of std::mbrtoc32() function in C++ STL.What is std::mbrtoc32()?std::mbrtoc32() function is an inbuilt function in C++ STL, which is defined in header file. This function is used to convert a narrow multibyte character to UTF-32-character representation.If the associated character pointer is not null, and all other parameters are also accepted then it will convert the corresponding 32-bit character.Syntaxsize_t mbrtoc32( char32_t* pc32, char* str, size_t n, mbstate_t* ps);ParametersThe function accepts following parameter(s) −pc32 − This is the pointer to the location we want the output to be stored.str − ... Read More

mbrtoc16() in C/C++ with Examples

Sunidhi Bansal
Updated on 17-Apr-2020 09:52:41

320 Views

In this article we will be discussing the working, syntax and examples of std::mbrtoc16() function in C++ STL.What is std::mbrtoc16()?std::mbrtoc16() function is an inbuilt function in C++ STL, which is defined in header file. This function is used to convert a narrow multibyte character to UTF-16-character representation.If the associated character pointer is not null, and all other parameters are also accepted then it will convert the corresponding 16-bit character.Syntaxsize_t mbrtoc16( char16_t* pc16, char* str, size_t n, mbstate_t* ps);ParametersThe function accepts following parameter(s) −pc16 − This is the pointer to the location we want the output to be stored.str − ... Read More

mbsrtowcs() function in C/C++

Sunidhi Bansal
Updated on 17-Apr-2020 09:35:08

183 Views

In this article we will be discussing the working, syntax and examples of std::mbsrtowcs() function in C++ STL.What is std::mbsrtowcs()?std::mbsrtowcs() function is an inbuilt function in C++ STL, which is defined in the header file. mbsrtowcs() means that it converts the null terminated multibyte character string whose first byte is *src to its wide character representation. This function returns the value according to the conversion.Syntaxsize_t mbsrtowcs( wchar_t* pwc, char** str, size_t n, mbstate_t* ps);ParametersThe function accepts following parameter(s) −pwc − This is the pointer to the location we want the output to be stored.str − Character string which is ... Read More

memcpy() in C/C++

Sunidhi Bansal
Updated on 17-Apr-2020 09:30:22

3K+ Views

In this article we will be discussing the working, syntax and examples of memcpy() function in C++ STL.What is memcpy()?memcpy() function is an inbuilt function in C++ STL, which is defined in header file. memcpy() function is used to copy blocks of memory. This function is used to copy the number of values from one memory location to another.The result of the function is a binary copy of the data. This function doesn’t check for any terminating source or any terminating null character, it just copies the num bytes from the source.Examplevoid memcpy( void* destination, void* source, size_t num);ParametersThe ... Read More

Advertisements