- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 7347 Articles for C++
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
89 Views
Here we will see how to get the length of each string element in the Numpy Array. Numpy is a library for Numeric Python, and it has very powerful array class. Using this we can store data in an array like structure. To get the length we can follow two different approach, these are like below −Exampleimport numpy as np str_arr = np.array(['Hello', 'Computer', 'Mobile', 'Language', 'Programming', 'Python']) print('The array is like: ', str_arr) len_check = np.vectorize(len) len_arr = len_check(str_arr) print('Respective lengts: ', len_arr)OutputThe array is like: ['Hello' 'Computer' 'Mobile' 'Language' 'Programming' 'Python'] Respective lengts: [ 5 8 6 8 ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
184 Views
Suppose we have an array of n elements. We have to find the first, second and the third minimum elements in the array. First minimum is the minimum of the array, second min is minimum but larger than the first one, and similarly the third min is minimum but greater than second min.Scan through each element, then check the element, and relate the condition for first, second and third min elements conditions to solve this problem.Example#include using namespace std; int getThreeMins(int arr[], int n) { int first = INT_MAX, sec = INT_MAX, third = INT_MAX; for ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
60 Views
Consider we have the initial values of two positive integers X and Y. Find the final value of X and Y, such that there will be some alteration as mentioned below −step1 − If X = 0 and Y = 0 then terminate the process, otherwise go to step2step2 − If X >= 2Y, then set X = X – 2Y, and go to step1, otherwise go to step3step3 − If Y >= 2X, then set Y = Y – 2X, and go to step1, otherwise end the process.The number X and Y will be in range [0 and 1018] ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
156 Views
Consider we have an array A, which is sorted. It has all elements appears twice, but one element is present for only one time. We have to find that element. If the array is [1, 1, 3, 3, 4, 4, 5, 6, 6, 7, 7, 9, 9], so the single element is 5.We will use the binary search approach to solve this. All elements before the single element has their first occurrence at index 0, 2, 4, … and first occurrence at index 1, 3, 5, … but after the single element, all occurrences of the first number will be ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
434 Views
Consider we have an integer n. Our task is to find two numbers a and b, where these three conditions will be satisfied.a mod b = 0a * b > na / b < nIf no pair is found, print -1.For an example, if the number n = 10, then a and b can be a = 90, b = 10. This satisfies given rules.To solve this problem, we will follow these steps −Let b = n. a can be found using these three conditionsa mod b = 0 when a is multiple of ba / b < n, so ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
121 Views
Suppose we have two numbers N and D. We have to find N digit number, that is divisible by D. If N is 3, and D is 5, then the number can be 500. This can be solved easily. If D is 10 and N is 1, then it will be impossible. We can put D, and suppose the D has m number of digits, then attach N – m number of 0s to make it N digit number and divisible by D.Example#include using namespace std; string nDigitDivByD(int n, int d) { string ans = ""; if (d ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
1K+ Views
Here we will see if a number is given, then how to find the value of Most Significant Bit value, that is set. The value is power of 2. So if the number is 10, MSB value will be 8.We have to find the position of MSB, then find the value of the number with a set-bit at kth position.Example#include #include using namespace std; int msbBitValue(int n) { int k = (int)(log2(n)); return (int)(pow(2, k)); } int main() { int n = 150; cout
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
304 Views
Consider we have a list of numbers; our task is to find the middle of the linked list using recursion. So if the list elements are [12, 14, 18, 36, 96, 25, 62], then the middle element is 36.To solve this problem, we will count total number of nodes in the list in recursive manner and do half of this. Then rolling back through recursion decrement n by 1 in each call, return element where n is zero.Example#include #include using namespace std; class Node{ public: int data; Node *next; }; Node* getNode(int data){ ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
554 Views
Consider we have a matrix, our task is to find the maximum element of each row of that matrix and print them. This task is simple. For each row, reset the max, and find the max element, and print it. Let us see the code for better understanding.Example#include #define MAX 10 using namespace std; void largestInEachRow(int mat[][MAX], int rows, int cols) { for (int i = 0; i < rows; i++) { int max_row_element = mat[i][0]; for (int j = 1; j < cols; j++) { if (mat[i][j] > max_row_element) max_row_element = mat[i][j]; } cout
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
430 Views
Consider we have a matrix, our task is to find the maximum element of each column of that matrix and print them. This task is simple. For each column, reset the max, and find the max element, and print it. Let us see the code for better understanding.Example#include #define MAX 10 using namespace std; void largestInEachCol(int mat[][MAX], int rows, int cols) { for (int i = 0; i < cols; i++) { int max_col_element = mat[0][i]; for (int j = 1; j < rows; j++) { if (mat[j][i] > max_col_element) max_col_element = mat[j][i]; } cout