 
 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 1312 of 2650
 
 
			
			5K+ Views
Definition: A number is that is greater than 2 and divisible only by itself and 1.Examples: Prime numbers are 2, 3, 5, 7, 11, 13, 113, 119, ..., etc.Approach to solve this problemStep 1: Find square root of the given number, sq_root = √numStep 2: If the given number is divisible by a number that belongs to [2, sq_root], then print “Non Prime Number”Step 3: If not divisible by any number, then print “Prime Number”ProgramLive Demopackage main import ( "fmt" "math" ) func checkPrimeNumber(num int) { if num < 2 { fmt.Println("Number must be greater than 2.") return } sq_root := int(math.Sqrt(float64(num))) for i:=2; i
 
 
			
			892 Views
ExamplesA1 = [2, 4, 6, 7, 8, 10, 3, 6, 0, 1]; Minimum number is 0;A2 = [12, 14, 16, 17, 18, 110, 13, 16, 10, 11]; Minimum number is 10;Approach to solve this problemStep 1: Consider the number at the 0th index as the minimum number, min_num = A[0].Step 2: Compare min_num with every number in the given array, while iterating.Step 3: If a number is smaller than min_num, then assign that number to min_num.Step 4: At the end of iteration, return min_num;ProgramLive Demopackage main import "fmt" func findMinElement(arr []int) int { min_num := arr[0] for i:=0; i
 
 
			
			649 Views
ExamplesA1 = [2, 4, 6, 7, 8, 10, 3, 6, 0, 1]; Maximum number is 10A2 = [12, 14, 16, 17, 18, 110, 13, 16, 10, 11]; Maximum number is 110Approach to solve this problemStep 1: Consider the number at the 0th index as the maximum number, max_num = A[0]Step 2: Compare max_num with every number in the given array, while iterating.Step 3: If a number is greater than max_num, then assign that number to max_num;Step 4: At the end of iteration, return max_num;ProgramLive Demopackage main import "fmt" func findMaxElement(arr []int) int { max_num := arr[0] for i:=0; i ... Read More
 
 
			
			99 Views
In this tutorial, we are going to write a program that finds the repeating element in the given array.Let's see the steps to solve the problem.Initialize the array.Initialize a counter map to store the frequency of each element in the array.Iterate over the array.Count each element.Print the element whose frequency is greater than 1.ExampleLet's see the code. Live Demo#include using namespace std; int findRepeatingElement(int arr[], int n) { map frequencies; for (int i = 0; i < n; i++) { map::iterator itr = frequencies.find(arr[i]); if (itr != frequencies.end()) { ... Read More
 
 
			
			320 Views
In this tutorial, we are going to solve the following problem.Given a tank with a capacity of N liters and a pump that fill the tank with S speed per minute. Unfortunately, there is a hole in the tank. And water is wasting at a speed of WS per minute while filling it.We need to calculate the amount of water wasted for a full tank.The amount of water filled per minute is equal to the difference between the water filling water and wasting water speed.Hence we can get the total time to fill the water tank by dividing the capacity ... Read More
 
 
			
			403 Views
In this tutorial, we are going to write a program that finds all the pairs whose sum is equal to the given number in the binary search tree.We are going to store and values of trees in two different lists to find the pairs. Let's see the steps to solve the problem.Create a struct node for a binary tree.Write a function to insert a new node into the binary search tree.Remember, in the binary search tree all the elements that are less than root are smaller, and right are larger.Initialize two empty lists to store the left and right nodes ... Read More
 
 
			
			2K+ Views
In this tutorial, we are going to write a program that finds all the divisors of a natural number. It's a straightforward problem. Let's see the steps to solve it.Initialize the number.Write a loop that iterates from 1 to the square root of the given number.Check whether the given number is divisible by the current number or not.If the above condition satisfies, then print the current number and given_number/current_number.ExampleLet's see the code. Live Demo#include using namespace std; void findDivisors(int n) { for (int i = 1; i
 
 
			
			6K+ Views
In this tutorial, we are going to write a program that finds all the divisors of a natural number. It's a straightforward problem. Let's see the steps to solve it.Initialize the number.Write a loop that iterates from 1 to the given number.Check whether the given number is divisible by the current number or not.If the above condition satisfies, then print the current number.ExampleLet's see the code. Live Demo#include using namespace std; void findDivisors(int n) { for (int i = 1; i
 
 
			
			438 Views
In this tutorial, we are going to write a program that finds the triplet in the array whose sum is equal to the given number.Let's see the steps to solve the problem.Create the array with dummy data.Write three inner loops for three elements that iterate until the end of the array.Add the three elements.Compare the sum with 0.If both are equal, then print the elements and break the loops.ExampleLet's see the code. Live Demo#include using namespace std; void findTripletsWithSumZero(int arr[], int n){ bool is_found = false; for (int i = 0; i < n-2; i++) { ... Read More
 
 
			
			256 Views
In this tutorial, we are going to write a program that finds the number whose XOR operation with the given number is maximum.We are assuming the number of bits here is 8.The XOR operation of different bits gives you the 1 bit. And the XOR operation between the same bits gives you the 0 bit.If we find the 1's complement of the given number, then that's the number we are looking for.ExampleLet's see the code. Live Demo#include using namespace std; int findNumberWithMaximumXOR(int X) { return ((1