List of prime numbers Write a C++ program to find the prime numbers between 100 and 10000 What is a prime number Definition: A number (N) is prime if it has no divisors except 1 and (N) Prime number calculator To check if (N) is prime we divide (N) by all numbers from 3 to
Swapping two variables without a temp Given two integer variables A and B. Write C++ code to swap them without using a temporary variable. Solution This is a well known problem for which you can find so many references on the Internet. One way to do that is to use addition and subtraction as follows:
Problem Write a C++ algorithm that takes a string as input then check if the input string is Palindrome. A Palindrome string reads the same from left to right and from right to left as in the following example: Rats live on no evil star Solution We need one pass through the characters of the
Problem A typical interview question is to describe an algorithm to reverse a string of characters. Solution We need one pass through the characters of the string to get the string length or use a built in function to get that. Once the length of the string is found then one for loop can be
Problem If you run the following block of java code. How many times the print statement is going to execute. Solution You can modify the code by adding a counter then let the code itself calculates how many times it executes however that is not what the problem is all about. You can trace the
Problem Write a Java program to find character counts in a string consisting from capital letters (A to Z) only. The program must not use nested loops. Hash tables that are built in to the language must not be used as well. For example if the input string is “CACBACDDDD” the output of the program
Find word count using perl Write a perl program that prints word count in file. For example if the input file contains the following word occurrences “Santa Clara is located in Santa Clara county” the program should print something like: Santa: 2 Clara: 2 is: 1 located: 1 in: 1 county: 1 Word count perl
Two arrays differences Given two integer arrays A and B of the same size each having no duplicate values. Write an equality function that returns true if A and B are equivalent. The arrays are equivalent if they contain the same content regardless of order. The function should return false if the arrays are not
Problem Write a Java class to implement a stack data structure using an array for storage. The stack must support pop and push operations. Java stack implementation A stack is a LIFO (last in first out) data structure. A push operation adds an element to the top of the stack. On the other hand a
Array recursive sum problem Given an array of N integers. Write a recursive function to calculate the sum of all elements in the array. Recursive sum algorithm The sum of N elements in a list is equivalent to the sum of one element of the array and the rest N-1 elements Code The following is