 
 Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Server Side Programming Articles - Page 2132 of 2650
 
 
			
			896 Views
Here we will see how to get the ceiling value of a/b without using the ceil() function. If a = 5, b = 4, then (a/b) = 5/4. ceiling(5/4) = 2. To solve this, we can follow this simple formula −$$ceil\lgroup a,b\rgroup=\frac{a+b-1}{b}$$Example Live Demo#include using namespace std; int ceiling(int a, int b) { return (a+b-1)/b; } int main() { cout
 
 
			
			372 Views
Suppose we have two vectors for two adjacent sides of a triangle in the form $x\hat{i}+y\hat{j}+z\hat{k}$ Our task is to find the area of triangle. The area of triangle is magnitude of the cross product of two vectors. (|A x B|)$$\frac{1}{2}\rvert \vec{A}\times\vec{B}\rvert=\frac{1}{2}\sqrt{\lgroup y_{1}*z_{2}-y_{2}*z_{1}\rgroup^{2}+\lgroup x_{1}*z_{2}-x_{2}*z_{1}\rgroup^{2}+\lgroup x_{1}*y_{2}-x_{2}*y_{1}\rgroup^{2}}$$Example Live Demo#include #include using namespace std; float area(float A[], float B[]) { float area = sqrt(pow((A[1] * B[2] - B[1] * A[2]), 2) + pow((A[0] * B[2] - B[0] * A[2]), 2) + pow((A[0] * B[1] - B[0] * A[1]), 2)); return area*0.5; } int main() { float A[] = {3, 1, -2}; ... Read More
 
 
			
			161 Views
Suppose we have two vectors for two adjacent sides of a parallelogram in the form $x\hat{i}+y\hat{j}+z\hat{k}$ Our task is to find the area of parallelogram. The area of parallelogram is magnitude of the cross product of two vectors. (|A × B|)$$\rvert \vec{A}\times\vec{B}\rvert=\sqrt{\lgroup y_{1}*z_{2}-y_{2}*z_{1}\rgroup^{2}+\lgroup x_{1}*z_{2}-x_{2}*z_{1}\rgroup^{2}+\lgroup x_{1}*y_{2}-x_{2}*y_{1}\rgroup^{2}}$$Example Live Demo#include #include using namespace std; float area(float A[], float B[]) { float area = sqrt(pow((A[1] * B[2] - B[1] * A[2]), 2) + pow((A[0] * B[2] - B[0] * A[2]), 2) + pow((A[0] * B[1] - B[0] * A[1]), 2)); return area; } int main() { float A[] = {3, 1, -2}; ... Read More
 
 
			
			599 Views
Consider we have a list of strings. The list has some duplicate strings. We have to check which strings are occurred more than once. Suppose the string list is like [“Hello”, “Kite”, “Hello”, “C++”, “Tom”, “C++”]Here we will use the hashing technique, so create an empty hash table, then traverse each string, and for each string, s is already present in the hash, then display the string, otherwise insert into the hash.Example Live Demo#include #include #include using namespace std; void displayDupliateStrings(vector strings) { unordered_set s; bool hasDuplicate = false; for (int i = 0; i
 
 
			
			434 Views
Here we will see how to get the equal points in a string of brackets. The equal point is the index I, such that the number of opening brackets before it is equal to the number of the closing bracket after it. Suppose a bracket string is like “(()))(()()())))”, if we see closer, we can getSo the number of opening brackets from 0 to 9 is 5, and the number of the closing brackets from 9 to 14 is also 5, so this is the equal point.To solve this problem, we have to follow these few steps −Store the number ... Read More
 
 
			
			749 Views
Suppose we have an array A, it has n elements. Our task is to divide the array A into two subarrays, such that the sum of each subarray will be the same. Suppose the array A = [2, 3, 4, 1, 4, 5], The output is 1, so subarrays before 1 and after 1 are taken. [2, 3, 4], and [4, 5].To solve this problem, we will calculate the whole array except for the first element in right_sum. Consider that is the partitioning element. We will traverse from left to right. Subtracting an element from right_sum and adding an element ... Read More
 
 
			
			404 Views
Consider we have an array A with few elements. We have to find an element from A, such that all elements can be divided by it. Suppose the A is like [15, 21, 69, 33, 3, 72, 81], then the element will be 3, as all numbers can be divisible by 3.To solve this problem, we will take the smallest number in A, then check whether all numbers can be divided by the smallest number or not, if yes, then return the number, otherwise, return false.Example Live Demo#include #include using namespace std; int getNumber(int a[], int n) { int minNumber ... Read More
 
 
			
			106 Views
Here we will see one problem, where we take a number n, we have to find another value say x, such that x + digit sum of x is same as the given number n. Suppose the value of n is 21. This program will return a number x = 15, as 15 + digit sum of 15, i.e. 15 + 1 + 5 = 21 = n.To solve this problem, we have to follow simple approach. We will iterate through 1 to n, in each iteration, we will see if the sum of the number and its digit sum ... Read More
 
 
			
			272 Views
Suppose we have one 3x3 matrix, whose diagonal elements are empty at first. We have to fill the diagonal such that the sum of a row, column and diagonal will be the same. Suppose a matrix is like −After filling, it will be −Suppose the diagonal elements are x, y, z. The values will be −x = (M[2, 3] + M[3, 2])/ 2z = (M[1, 2] + M[2, 1])/ 2y = (x + z)/2Example Live Demo#include using namespace std; void displayMatrix(int matrix[3][3]) { for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) cout
 
 
			
			74 Views
Suppose we have a container with size X. It has a mixture of water and other liquid, the mixture has W% of water in it. We have to find how many water must be added to increase the ratio of water to Y%? If X = 125, W = 20 and Y = 25, then output will be 8.33 liters.Suppose we have to add A amount of water with the previous mixture, so new amount will be X + A. So the amount of water in the mixture will follow this formula.Old Amount+A=((W% of X) + A)Also the amount of ... Read More