Sunidhi Bansal has Published 1101 Articles

Print prime numbers with prime sum of digits in an array

Sunidhi Bansal

Sunidhi Bansal

Updated on 30-Jul-2019 22:30:26

480 Views

Given with an array of elements and the task is to print those numbers whose digit sum is also prime and return -1 is not such digit exists in an arrayInput: arr[]={2, 4, 3, 19, 25, 6, 11, 12, 18, 7} Output : 2, 3, 25, 11, 12, 7Here, the ... Read More

Print numbers having first and last bits as the only set bits

Sunidhi Bansal

Sunidhi Bansal

Updated on 30-Jul-2019 22:30:26

135 Views

The task is to print the given n number which have exactly two set bits that neither less than 2 nor more than 2.Set bits in computer language are the one that have value 1 and unset bits have value as 0Input: value of num=5 Output: 1 3 5   ... Read More

Print Postorder traversal from given Inorder and Preorder traversals

Sunidhi Bansal

Sunidhi Bansal

Updated on 30-Jul-2019 22:30:26

871 Views

Given with inorder and preorder of a tree program must find the postroder traversal and print the sameInput: Inorder traversal in[] = {4, 2, 5, 1, 3, 6} Preorder traversal pre[] = {1, 2, 4, 5, 3, 6} Output: Postorder traversal post[] = {4, 5, 2, 6, 3, 1}AlgorithmSTART Step ... Read More

Print Reverse a linked list using Stack

Sunidhi Bansal

Sunidhi Bansal

Updated on 30-Jul-2019 22:30:26

902 Views

Given with a linked list program must print the list starting from the end till the front using the stack data structureInput : 10 -> 5 -> 3 -> 1 -> 7 -> 9 Output: 9 -> 7 -> 1 -> 3 -> 5 -> 10Here the user can use ... Read More

Print the nearest prime number formed by adding prime numbers to N

Sunidhi Bansal

Sunidhi Bansal

Updated on 30-Jul-2019 22:30:26

257 Views

As per the question, the task is to find the nearest prime number by adding the prime number starting from 2 if the number N is not Prime.Input: N=6 Output: 11ExplanationSince 6 is not prime add first prime to 6 i.e. 2 which will result to 8 now 8 is ... Read More

Print N lines of numbers such that every pair among numbers has a GCD K

Sunidhi Bansal

Sunidhi Bansal

Updated on 30-Jul-2019 22:30:26

106 Views

GCDGCD stands for Greatest Common Divisor of two or more integers excluding 0Like, to find the greatest common divisor of 48 and 18048 = 2 × 2 × 2 × 2 × 3180 = 2 × 2 × 3 × 3 × 5Greatest common divisor = 2 × 2 × ... Read More

Print the kth common factor of two numbers

Sunidhi Bansal

Sunidhi Bansal

Updated on 30-Jul-2019 22:30:26

232 Views

Given with two numbers x and y the output should contain their kth common factor.Input: x=9 y=18 k=1 Output : k common factor = 2 Factors of 9 : 1, 3, 9 Factors of 18 : 1, 2, 3, 6, 9, 18 Greatest Common Factor : 9AlgorithmSTART Step 1 -: ... Read More

Print n terms of Newman-Conway Sequence

Sunidhi Bansal

Sunidhi Bansal

Updated on 30-Jul-2019 22:30:26

255 Views

Newman-Conway Sequence is used for generating following integer sequence.1 1 2 2 3 4 4 4 5 6 7 7 8 8 8 8 9 10 11 12Formula used for generating Newman-Conway sequence for n numbers is −P(n) = P(P(n - 1)) + P(n - P(n - 1)) Where, p(1) ... Read More

Print n smallest elements from given array in their original order

Sunidhi Bansal

Sunidhi Bansal

Updated on 30-Jul-2019 22:30:26

167 Views

Given with array of let’s say k elements the program must find the n smallest elements amongst them in their appearing order.Input : arr[] = {1, 2, 4, 3, 6, 7, 8}, k=3 Ouput : 1, 2, 3 Input k is 3 it means 3 shortest elements among the set ... Read More

Print values of ‘a’ in equation (a+b) <= n and a+b is divisible by x

Sunidhi Bansal

Sunidhi Bansal

Updated on 30-Jul-2019 22:30:26

55 Views

Given with equation program must find the value of ‘a’ where a+b Declare start variables b=10, x=9, n=40 and flag=0, divisible Step 2 -> Loop For divisible = (b / x + 1 ) * x and divisible = 1       Print divisible-1       Set flag=1 ... Read More

Advertisements