Transwiki:Programming problems

This page gives a list of programming problems. These are useful for anyone who wants to learn programming quickly. Each problem has a problem statement and the required output along with multiple solutions (including flawed and ill-performing solutions).

3n + 1 problem
 * Hello world - Write a program to display &#8220;Hello world&#8221;


 * Addition of 2 numbers - Write a program to add two numbers


 * Greatest of 3 numbers - Find the greatest of three numbers


 * Greatest of N numbers - Find the greatest of N numbers where N is any arbitrary natural number


 * Factorial or Product of N numbers - Given N as input find N! Example: N = 4; output is 24 because 1 x 2 x 3 x 4 = 24


 * Average of N numbers - Find the average of N numbers


 * Generate prime numbers - Write a program to generate N prime numbers


 * Prime or not - Determine whether given number N is prime or not


 * Generate Fibonacci series - Write a program to generate the Fibonacci series which goes like this 1, 1, 2, 3, 5, 8, 13, 21..


 * Factorization - Break down a number into its prime factors


 * Lowest common divisor - Write a program to determine the lowest common divisor for two numbers


 * Lowest common divisor for N numbers - Write a program to determine the lowest common divisor for N numbers


 * Highest common factor - Find the highest common factor for the two given numbers


 * Highest common factor for N numbers - Find the highest common factor for the N given numbers


 * Quadratic roots - Find the roots of a quadratic equation Ax2 + Bx + C = 0 given the coefficients A, B, C

i)	Circle ii)	Square iii)	Rectangle iv)	Cuboid v)	Sphere vi)	Cone vii)	Cylinder
 * Area and volume - Write a program to determine the areas and/or volumes of the following geometric entities

Arithmetic &#8226;	1, 2, 3, 4, ... &#8226;	1, 3, 5, 7, 9, ... &#8226;	2, 4, 6, 8, &#8230; &#8226;	10, 15, 20, 25 &#8230;
 * Number Series generation -

Geometric &#8226;	2, 4, 8, 16 &#8230; &#8226;	10, 100, 1000, 10000, &#8230; &#8226;	3, 27, 243, &#8230;


 * Evaluate cos(x), sin(x) - Write a program to determine the sine and cosine value of given input x.

Ask the user to guess a number between 1 and 100. Try to guess it using the following logic. Say user has chosen number 80 Prog: Is number 50? User: G (My number is greater than that) Prog: Is number 75? User: G Prog: Is number 87? User: L (My number is lesser than that) Prog: Is number 81? User: L (My number is lesser than that) Prog: Is number 78? User: G Prog: Is number 79? User: G Prog: Is number 80? User: Y
 * Guess the number -

Example: Input N is 4219 (say) Output should be 4, 2, 1, 9
 * Digits of a Number - Write a program to display the digits of a number.

Example: The given digits are 4, 2, 1, 9 Output should be 4219
 * Number from digits - Write a program to generate the number given the digits

Example: Output should be 9124 given 4219
 * Reverse a number - Write a program to reverse a number

Input: 7331 (is super prime) Input: 4550 (is not super prime) Hint: 7331 is super-prime because, 7331, 733, 73 and 7 are primes
 * Super-prime - Write a program to find whether N is a super-prime or not

Hint: A number is Armstrong if the sum of cubes of its digits is equal to the number itself Input: 371 (is Armstrong) Input: 456 (is not Armstrong)
 * Armstrong number - Write a program to determine whether a number is Armstrong number or not


 * Generate list of random numbers - Write a program to use an inbuilt library function to generate a list of random numbers. Also try as an added exercise to write a pseudo-random number generator


 * Print ASCII table - Write a program to print the ASCII code and the corresponding character in the form of a table


 * Matrix addition


 * Matrix Multiplication


 * Palindrome


 * Printing practice (Stars and numbers)


 * String manipulation (String concatenation, sub string, remove spaces)


 * Search and replace in strings


 * Time and date display


 * Date difference


 * Eight queens solution checking


 * Eight queens recursive solution


 * Eight queens non-recursive solution


 * Permutations


 * Combinations


 * Anagram checking


 * Anagram generation


 * Number system conversion


 * Travelling salesman problem


 * Bin-Packing problem


 * Sort N numbers


 * Sort strings in array


 * Linear search


 * Binary search


 * Hashing


 * Indexing


 * Binary trees


 * B+ trees


 * Linked list


 * Adaptive multiple choice quiz


 * Telephone directory


 * Expression solving


 * Caesar encryption


 * XOR encryption


 * Random name generation


 * Copy and move files


 * List all directories using recursion and without


 * Spawn a shell process


 * Run two threads


 * Calculator


 * Stack


 * Queues


 * Curve fitting


 * Line fitting


 * Solution of Linear equations


 * Minimax search


 * Preprocessor for C


 * Expression evaluation


 * Sorting in Files


 * Leap year


 * Calendar generation


 * Arithmetic encoding


 * LZW text compression


 * RSA encryption


 * DES encryption


 * Polyalphabetic and Monoalphabetic encryption