Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
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 2168 of 2650
218 Views
Here we will see how to check a number is divisible by 20 or not. In this case the number is very large number. So we put the number as string.A number will be divisible by 20, when that is divisible by 10, and after dividing 10, the remaining number is divisible by 2. So the case is simple. If the last digit is 0, then it is divisible by 10, and when it is divisible by 10, then the second last element is divisible by 2, the number is divisible by 20.Example Live Demo#include using namespace std; bool isDiv20(string ... Read More
272 Views
Here we will see how to check a number is divisible by 2, 3 and 5 or not. In this case the number is very large number. So we put the number as string.A number will be divisible by 2, 3 and 5 if that number is divisible by LCM of 2, 3 and 5. So the LCM of 2, 3, 5 is 30. We have to check the number is divisible by 30 or not. A number is divisible by 30 when it is divisible by 10 (last digit is 0) and divisible by 3 (sum of all digits ... Read More
637 Views
In this article, we are given a larger number and we need to check whether it is divisible by 11 or not using the C++ program. To handle large numbers, we treat the number as a string and apply a divisibility rule to check if it's divisible by 11. Rule of Divisibility by 11 A number is divisible by 11 if the difference between the sum of its digits at odd positions and the sum of its digits at even positions is divisible by 11. Consider the following example scenarios to understand the divisibility of a large number ... Read More
179 Views
Here we will see how to check a number is divisible by 15 or not. In this case the number is very large number. So we put the number as string.To check whether a number is divisible by 15, if the number is divisible by 5, and divisible by 3. So to check divisibility by 5, we have to see the last number is 0 or 5. To check divisibility by 3, we will see the sum of digits are divisible by 3 or not.Example Live Demo#include using namespace std; bool isDiv15(string num){ int n = num.length(); if(num[n ... Read More
438 Views
Here we will see how to check a string is made up of alternating characters or not. If a string is like XYXYXY, it is valid, if a string is like ABCD, that is invalid.The approach is simple. We will check whether all ith character and i+2 th character are same or not. if they are not same, then return false, otherwise return true.Example Live Demo#include using namespace std; bool hasAlternateChars(string str){ for (int i = 0; i < str.length() - 2; i++) { if (str[i] != str[i + 2]) { return ... Read More
2K+ Views
In this article, we will learn about the solution and approach to solve the given problem statement.Problem statementGiven a range, we need to print all the even numbers in the given range.The brute-force approach is discussed below −Here we apply a range-based for loop which provides all the integers available in the input interval.After this, a check condition for even numbers is applied to filter all the odd numbers.This approach takes O(n) + constant time of comparison.Now let’s see the implementation below −Examplestart, end = 10, 29 # iteration for num in range(start, end + 1): # check ... Read More
264 Views
In this article, we will learn about the solution and approach to solve the given problem statement.Problem statementGiven a number n, we need to check whether the given number is a power of two.ApproachContinue dividing the input number by two, i.e, = n/2 iteratively.We will check In each iteration, if n%2 becomes non-zero and n is not 1 then n is not a power of 2.If n becomes 1 then it is a power of 2.Let’s see the implementation below −Exampledef isPowerOfTwo(n): if (n == 0): return False while (n != 1): ... Read More
489 Views
In this article, we will learn about the solution and approach to solve the given problem statement.Problem statementGiven an input string we need to find the most occurring character and its count.ApproachCreate a dictionary using Counter method having strings as keys and their frequencies as values.Find the maximum occurrence of a character i.e. value and get the index of it.Now let’s see the implementation below −Examplefrom collections import Counter def find(input_): # dictionary wc = Counter(input_) # Finding maximum occurrence s = max(wc.values()) i = wc.values().index(s) print (wc.items()[i]) # Driver program if __name__ ... Read More
3K+ Views
In this article, we will learn about the solution and approach to solve the given problem statement.Problem statementGiven a dictionary, we need to find the three highest valued values and display them.Approach 1 − Using the collections module ( Counter function )Example Live Demofrom collections import Counter # Initial Dictionary my_dict = {'t': 3, 'u': 4, 't': 6, 'o': 5, 'r': 21} k = Counter(my_dict) # Finding 3 highest values high = k.most_common(3) print("Dictionary with 3 highest values:") print("Keys: Values") for i in high: print(i[0], " :", i[1], " ")OutputDictionary with 3 highest values: Keys: Values r : 21 t ... Read More
1K+ Views
In this article, lets see try to find the sum of elements in a list. For a given integer list, the program should return the sum of all elements of the list. For an example let's consider list_1 = [1, 2, 3, 4, 5] the output of the program should be 15. Following are the different types of approaches to find the sum of elements in a list − Iterating through loops Using Recursion Using sum() function By ... Read More