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 2231 of 2650
609 Views
Here we will see how we can concatenate a string n number of times. The value of n is given by the user. This problem is very simple. In C++ we can use + operator for concatenation. Please go through the code to get the idea.AlgorithmconcatStrNTimes(str, n)begin res := empty string for i in range 1 to n, do res := concatenate res and res done return res endExample Live Demo#include using namespace std; main() { string myStr, res = ""; int n; cout > myStr; cout > n; for(int i= 0; i < n; i++) { res += myStr; } cout
630 Views
In this problem we will see how we can get the sum of squares of first n natural numbers. Here we are using one for loop, that runs from 1 to n. In each step we are calculating square of the term and then add it to the sum. This program takes O(n) time to complete. But if we want to solve this in O(1) or constant time, we can use this series formula −AlgorithmsquareNNatural(n)begin sum := 0 for i in range 1 to n, do sum := sum + i^2 done return ... Read More
1K+ Views
In the crypt-arithmetic problem, some letters are used to assign digits to it. Like ten different letters are holding digit values from 0 to 9 to perform arithmetic operations correctly. There are two words are given and another word is given as answer of addition for those two words. As an example we can say that two words ‘BASE’ and ‘BALL’, and the result is ‘GAMES’. Now if we try to add BASE and BALL by their symbolic digits, we will get the answer GAMES.NOTE − There must be ten letters maximum, otherwise it cannot be solved.InputThis algorithm will take ... Read More
273 Views
In this problem we will try to find smallest K-digit number, that will be divisible by X. To do this task we will take the smallest K digit number by this formula (10^(k-1)). Then check whether the number is divisible by X or not, if not, we will get the exact number by using this formula.(min+ 𝑋)−((min+ 𝑋) 𝑚𝑜𝑑 𝑋)One example is like a 5-digit number, that is divisible by 29. So the smallest 5-digit number is 10000. This is not divisible by 29. Now by applying the formula we will get −(10000+ 29)−((10000+29) 𝑚𝑜𝑑 29)=10029−24=10005The number 10005 is divisible ... Read More
200 Views
Here we will see how we can get the gcd of more than two numbers. Finding gcd of two numbers are easy. When we want to find gcd of more than two numbers, we have to follow the associativity rule of gcd. For example, if we want to find gcd of {w, x, y, z}, then it will be {gcd(w, x), y, z}, then {gcd(gcd(w, x), y), z}, and finally {gcd(gcd(gcd(w, x), y), z)}. Using array it can be done very easily.Algorithmgcd(a, b)begin if a is 0, then return b end if return gcd(b ... Read More
329 Views
Here we will see how we can get the number of common divisors of two numbers. We are not going to find all common divisors, but we will count how many common divisors are there. If two numbers are like 12 and 24, then common divisors are 1, 2, 3, 4, 6, 12. So there are 6 common divisors, so the answer will be 6.AlgorithmcountCommonDivisor(a, b)begin count := 0 gcd := gcd of a and b for i := 1 to square root of gcd, do if gcd is divisible by 0, then ... Read More
299 Views
We are given n binary strings, and we need to add them together and return the result (as a binary string). A binary string is a string that consists only of the characters '0' and '1', which represent binary digits. We will add them bit by bit using binary addition rules. Addition of Binary Numbers Here's how binary addition with binary numbers works: 1 + 0 = 1 0 + 1 = 1 0 + 0 = 0 1 + 1 ... Read More
149 Views
Suppose there is an array with some numbers. We have to tell minimum how many numbers will be added with it to make the sum of the elements even. The number must be greater than 0. So if the sum of the elements is odd, we will add 1, but if the sum is already even, then we will add 2 with it to make it even.AlgorithmaddMinNumber(arr)begin s := 0 for each element e from arr, do s := e + s done if s is even, then return 2, otherwise 1 endExample Live ... Read More
2K+ Views
The Adam number is a number such that the square of the given number 'n' is the reverse of the square of the reverse of that number 'n'. In this article, our task is to write a program that can check whether the given number is an Adam number or not. Here is an example to check whether 12 is an Adam number or not: Input: num = 12 Output: 12 is an Adam number Explanation: num = 12 , square of num = ... Read More
2K+ Views
There are n different activities are given with their starting time and ending time. Select maximum number of activities to solve by a single person.We will use the greedy approach to find the next activity whose finish time is minimum among rest activities, and the start time is more than or equal with the finish time of the last selected activity.The complexity of this problem is O(n log n) when the list is not sorted. When the sorted list is provided the complexity will be O(n).InputA list of different activities with starting and ending times.{(5, 9), (1, 2), (3, 4), ... Read More