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 1028 of 2650
1K+ Views
Given a number n, we need to find the count of multiples of 3 or 7 till n. Let's see an example.Input100Output43There are total of 43 multiples of 3 or 7 till 100.AlgorithmInitialise the number n.Initialise the count to 0.Write a loop that iterates from 3 to n.Increment the count if the current number is divisible by 3 or 7.ImplementationFollowing is the implementation of the above algorithm in C++#include using namespace std; int getMultiplesCount(int n) { int count = 0; for (int i = 3; i
663 Views
We can find the multiples using % operator without any hurdles. But, the problem states that we can't use % operator.Here, we make use of the + operator. We can get the multiples by adding 3 or 5 to the previous multiple. Let's see an example.Input15Output1 2 3 - Multiple of 3 4 5 - Multiple of 5 6 - Multiple of 3 7 8 9 - Multiple 3 10 - Multiple of 5 11 12 - Multiple of 3 13 14 15 - Multiple of both 3 and 5AlgorithmInitialise the number n.Initialise two number to keep track of next ... Read More
878 Views
Given a linked list, we have to move the last element to the front. Let's see an example.Input1 -> 2 -> 3 -> 4 -> 5 -> NULLOutput5 -> 1 -> 2 -> 3 -> 4 -> NULLAlgorithmInitialise the linked list.Return if the linked list is empty or it has single node.Find the last node and second last nodes of the linked list.Make the last node as new head.Update the link of second last node.ImplementationFollowing is the implementation of the above algorithm in C++#include using namespace std; struct Node { int data; struct Node* next; }; void ... Read More
383 Views
Given a linked list with random integers and zeroes. We have to move all the zeroes to the front of the linked list. Let's see an example.Input3 -> 0 -> 1-> 0 -> 0 -> 1 -> 0 -> 0 -> 3 -> NULLOutput0->0->0->0->0->3->1->1->3->NULL AlgorithmInitialise the linked list.Return if the linked list is empty or it has single node.Initialise two nodes with second node and first node respectively to track current and previous nodes.Iterate over the linked list until we reach the end.If the current node is 0, then make it new head.Update the values of current and previous nodes ... Read More
850 Views
In this tutorial, we are going to write a program that moves all zeroes to front and ones to end of the array.Given an array with zeroes and ones along with random integers. We have to move all the zeroes to start and ones to the end of the array. Let's see an example.Inputarr = [4, 5, 1, 1, 0, 0, 2, 0, 3, 1, 0, 1]Output0 0 0 0 4 5 2 3 1 1 1 1AlgorithmInitialise the array.Initialise an index to 1.Iterate over the given array.If the current element is not zero, then update the value at the ... Read More
3K+ Views
Given array with multiple zeroes in it. We have to move all the zeroes in the array to the end. Let's see an example.Inputarr = [4, 5, 0, 3, 2, 0, 0, 0, 5, 0, 1]Output4 5 3 2 5 1 0 0 0 0 0AlgorithmInitialise the array.Initialise an index to 0.Iterate over the given array.If the current element is not zero, then update the value at the index with the current element.Increment the index.Write a loop that iterates from the above index to nUpdate all the elements to 0.ImplementationFollowing is the implementation of the above algorithm in C++#include ... Read More
216 Views
The Motzkin number series starts with 1, 1, 4, 9, etc.., We can get the generalised nth term with the sequence. The Motzkin number sequence is as follows.a0 = 1a1 = 1a2 = 4a3 = 9an = ((2 * n + 1)/ n + 2) * M(n-1) +((3 * n - 3)/ n + 2) * M(n - 2)AlgorithmInitialise the number n.Iterate till n.Update the previous two numbersReturn the last number.ExampleImplementationFollowing is the implementation of the above algorithm in C++#include using namespace std; int getNthTerm(int n) { if(n == 0 || n == 1) { return 1; } int a = 1, b = 1; for(int i = 2; i
246 Views
We are given a number N. We need to find the prime palindrome that is greater than N. Let's see an example.InputN = 10Output11AlgorithmInitialise the number N.Write a function to check whether the given number is prime or not.Write a function to check whether the given number is palindrome.Write a loop that iterates from N + 1 till you find the next prime palindrome.Check if the number is prime and palindrome.If the number is prime and palindrome.Return the number.ImplementationFollowing is the implementation of the above algorithm in C++#include using namespace std; bool isPrime(int n) { if (n < 2) ... Read More
1K+ Views
The next smaller element is the element that is the first smaller element after it. Let's see an example.arr = [1, 2, 3, 5, 4]The next smaller element for 5 is 4 and the next smaller element for elements 1, 2, 3 is -1 as there is no smaller element after them.AlgorithmInitialise the array with random numbersInitialise a stack.Add first element to the stack.Iterate through the element of the array.If the stack is empty, add the current element to the stack.While the current element is smaller than the top element of the stack.Print the top element with the next smaller ... Read More