Found 34494 Articles for Programming

Python program to print check board pattern of n*n using numpy

karthikeya Boyini
Updated on 30-Jul-2019 22:30:23

846 Views

Given the value of n, our task is to display the check board pattern for a n x n matrix. Different types of functions to create arrays with initial value are available in numpy . NumPy is the fundamental package for scientific computing in Python. Algorithm Step 1: input order of the matrix. Step 2: create n*n matrix using zeros((n, n), dtype=int). Step 3: fill with 1 the alternate rows and columns using the slicing technique. Step 4: print the matrix. Example Code import numpy as np def checkboardpattern(n): print("Checkerboard pattern:") ... Read More

Prefix sum array in python using accumulate function

karthikeya Boyini
Updated on 25-Jun-2020 11:31:53

382 Views

Given an array and we have to do the prefix sum array using accumulate function.itertools.accumulate(iterable[, func]) module functions all construct and return iterators. So they should only be accessed by functions or loops that truncate the stream. Make an iterator that returns accumulated sums. Elements may be any addable type including Decimal or Fraction. If the optional function argument is supplied, it should be a function of two arguments and it will be used instead of addition.ExampleInput Data = [1, 0, 2, 3, 5] >>> list(accumulate(data)) # running summation Output [1, 1, 3, 6, 11]AlgorithmStep 1: Create list. Step 2: ... Read More

Python program using map function to find row with maximum number of 1's

AmitDiwan
Updated on 11-Aug-2022 09:03:32

211 Views

In this article, we will learn how to use map function to find row with maximum number of 1's. 2D array is given and the elements of the arrays are 0 and 1. All rows are sorted. We have to find row with maximum number of 1's. Here we use map (). The map function is the simplest one among Python built-ins used for functional programming. These tools apply functions to sequences and other iterables. Let’s say the input is the following array − [[0, 1, 1, 1, 1], [0, 0, 1, 1, 1], [1, 1, 1, 1, 1], [0, ... Read More

New Features of C++17

Ankith Reddy
Updated on 30-Jul-2019 22:30:23

368 Views

C++17 is the latest version of standard C++ language. C++11 and C++14 are the previous versions of C++. The current version makes several additions to the core language while some previous features are also removed. C++17 is known as feature full or feature complete. There are some of the new changes introduced in C++17 − Library changes - utils This is one of the most amazing feature of C++17. It merges the features and patterns of other libraries. Many of the sub-libraries are merged together into standards. The following features are added to utils library in C++17 − std::variant ... Read More

Difference between strncmp() and strcmp() in C/C++

George John
Updated on 12-Sep-2023 03:17:26

1K+ Views

strncmp()The function strncmp() is used to compare left string to right string up to a number. It works same as strcmp(). It returns a value greater than zero when the matching character of left string has greater ASCII value than the character of the right string. Returns a value less than zero when the matching character of left string has lesser ASCII value than the character of the right string.Here is the syntax of strncmp() in C language, int strncmp ( const char *leftString, const char *rightString, size_t number );Here, leftString  − The first string which is to be compared ... Read More

C++ Scope resolution operator

Chandu yadav
Updated on 25-Jun-2020 10:21:24

20K+ Views

The scope resolution operator ( :: ) is used for several reasons. For example: If the global variable name is same as local variable name, the scope resolution operator will be used to call the global variable. It is also used to define a function outside the class and used to access the static variables of class.Here an example of scope resolution operator in C++ language,Example Live Demo#include using namespace std; char a = 'm'; static int b = 50; int main() {    char a = 's';    cout

How to convert a single character to string in C++?

Arjun Thakur
Updated on 25-Jun-2020 10:09:24

157 Views

There are several methods to convert a single character to a string. In the following example, some of them are used to convert a character to a string.Here is an example of converting a single character to string in C++ language,Example Live Demo#include #include #include int main() {    char c = 'm';    std::string s(1, c);    std::cout

remquo() in C++

Ankith Reddy
Updated on 25-Jun-2020 10:09:57

46 Views

The function remquo() is used to calculate the floating point remainder of numerator or denominator and stores the quotient to the passed pointer. It returns Nan(Not a number) when denominator is zero.Here is the syntax of remquo() in C++ language, float remquo(float var1, float var2, int* var3);Here, var1  − The variable which stores the value of numerator.var2  − The variable which stores the value of denominator.var3  − The pointer variable which stores the quotient.Here is an example of remquo() in C++ language, Example Live Demo#include #include using namespace std; int main() {    float x = 28.8; ... Read More

ldexp() in C++

George John
Updated on 25-Jun-2020 10:10:32

73 Views

The function ldexp() is used to calculate the multiplication of a floating point value ‘a’ by the number 2 raised to the exponent power. It takes two arguments, first is a floating point number and second is an integer value.Here is the mathematical expression of ldexp(), ldexp() = a * 2^bHere is the syntax of ldexp() in C++ language, float ldexp(float variable1 , int variable2)Here, variable1  − Any name given to the variable which is representing the significand.variable2  − Any name given to the variable which is representing the exponent.Here is an example of ldexp() in C++ language, Example Live Demo#include ... Read More

expm1() in C++

Chandu yadav
Updated on 25-Jun-2020 10:11:08

36 Views

The function expm1() is used to calculate the exponential raised to the power of any number minus one. It returns the value of (exponential raised to the power of a) - 1.Here is the mathematical expression of expm1(),expm1(a) = (e^a) - 1Here is the syntax of expm1() in C++ language,float expm1(variable_name);Here,variable_name − Any name given to the variable whose value is calculated.Here is an example of expm1() in C++ language,Example Live Demo#include #include using namespace std; int main() {    int x = 10;    float y = 8.28;    cout

Advertisements