In c++ programming language, there are keywords that can be used in place of logical operators. The keywords are initially used in c when the keyboards didn’t support symbols like &&, !, ||, etc. Now, here are some written version of logical operators in c++.Operators and their written versions are −OperatorSymbolsWritten versionAnd operator&&andOr operator||orNot operator!notNot equal to operator!=not_eqBitwise and operator&bitandBitwise or operator|bitorBitwise XOR operator^And equal to operator&=and_eqOr equal to operator|=or_eqXOR equal to operator^=Program to show the implementation of our programExample Live Demo#include using namespace std; int main(){ int x=1, y=0; coutRead More
In this problem, we are given an array of n elements and an integer value k. Our task is to find XOR of all elements of the array that have set bits equal to k.Let’s take an example to understand the problem, Inputarray = {2, 12, 44, 103, 17} , K =3Output44To solve this problem, we will count set bit of every element of the array and compare it with k. If the number of set bits is equal to k, then we will push it to a vector and find XOR of all elements of the vector.For finding the ... Read More
You can pass the parameters in the PowerShell function and to catch those parameters, you need to use the arguments. Generally, when you use variables outside the function, you really don’t need to pass the argument because the variable is itself a Public and can be accessible inside the function. But in some cases we need to pass the parameters to the function and below is the example explains how you can write the code for it.The single parameter passed in function, function writeName($str){ Write-Output "Hi! there .. $str" } $name = Read-Host "Enter Name" writeName($name)Here, we are passing ... Read More
Generally, when the variable is declared as a Public variable or outside the function in the script (not in any other variable or condition), you don’t need to pass that value to function because the function retains the value of the variable when the variable is initialized before the function is called.Examplefunction PrintOut{ Write-Output "your Name is : $name" } $name = Read-Host "Enter your Name" PrintOutIn the above example, $name variable is declared outside the function called PrintOut. So as the variable can be read inside the function, you can directly use the variable by its name.OutputEnter your ... Read More
Function in a PowerShell is to reduce the redundancy of the repeated codes this means codes which are repeating, bind them into a function and call the function whenever necessary, so you don’t need to write codes multiple times.ExampleLet assume, you want to perform arithmetic operations (multiply, sum, divide and subtraction) of two values 5 and 4 in one go, so you will write different operations for two values or you will assign values to the variable called $val1 and $val2 and perform various operations on them as shown below in the example.$val1 = 5 $val2 = 4 $val1 ... Read More
XOR cipher or XOR encryption is a data encryption method that cannot be cracked by brute-force method.Brute-force method is a method of random encryption key generation and matching them with the correct one.To implement this encryption method, we will define an encryption key(random character) and perform XOR of all characters of the string with the encryption key. This will encrypt all characters of the string.Program to show the implementation of encryption −Example Live Demo#include #include using namespace std; void XORChiper(char orignalString[]) { char xorKey = 'T'; int len = strlen(orignalString); for (int i = 0; i < len; ... Read More
In this problem, we are given an arr[] and some queries that are range between L to R in the array. Our task is to print the XOR of the subarray between L to R.Let’s take an example to understand the problem, Input − array = {1, 4, 5, 7, 2, 9} L = 1 , R = 5Output −Explanation − 4^5^7^2^9To solve this problem, we will create an array, based on the following observation, We will XOR multiple bits, if there are odd number of 1s, the result will be 1 otherwise the result is 0.Now, we will create ... Read More
We are given with a variable of any type and the task is to find the result using the function log1p(). log1p() is an analytical function that takes an argument ‘a’ and also has a return value.Syntaxdouble log1p (double x); Where x ranges between [-1, ?] float log1p (float x);Return Type − This function returns a non-zero value if the argument is greater than -1 else it will return a non-numeric value.ExampleInputa = 20.34Output3.06058Inputa = 0.0Output0Example Live Demo#include #include using namespace std; int main(){ double ans = 20.34; double temp; temp = log1p(ans); cout
In this article we will be discussing the working, syntax and examples of std::mbrtowc() function in C++ STL.What is std::mbrtowc()?std::mbrtowc() function is an inbuilt function in C++ STL, which is defined in the header file. mbrtowc() means that it converts the narrow multibyte character string to wide character. This function is used to convert a narrow multibyte character to wide character representation.Syntaxsize_t mbrtowc( 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 used as the ... Read More
Z algorithm is used to find the occurrence of a pattern in a string in linear time. Suppose if the length of the string is n and the size of the pattern to be searched is m, the time taken to solve will be of the order O(m+n).The z-algorithm uses a Z array to find the occurrence of a pattern.Z arrayIt is an array of the same length as the string. Each element of the z-array consists of the length of the longest substring of the string starting from I which can be used as a prefix of the string ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP